Introduction
Making sure that your data are appropriately ordered within a dataset can simplify analysis. In this blog entry, we’ll show you how to order your variables in Stata.
Create Data
First, we’ll create mock data, then we’ll show you some approaches to ordering.
set obs 30
gen q1_a = runiform(1,7)
gen q2_a = runiform(1,7)
gen q3_a = runiform(1,7)
gen q4_a = runiform(1,7)
gen q2 = round(q2_a)
gen q3 = round(q3_a)
gen q1 = round(q1_a)
gen q4 = round(q4_a)
drop q1_a q2_a q3_a q4_a
gen subj = _n
label variable subj "Subject #"
list in 1/30
Order Variables
Let’s say that you want the variables to be ordered subj, q1, q2, q3, and q4. Simply type:
order subj q1 q2 q3 q4
list in 1/30
That’s the order you were looking for.
BridgeText can help you with all of your statistical analysis needs.