Hello,
I am having troubles creating loops when naming variables.
I am using Stata/IC 15.1 for Windows.
When I uploaded the data into Stata from an NCES csv file, it named the variables v1, v2, v3, etc.
I had to rename these, so I did the following:
insheet using C:\Users\Mike\Desktop\Stata\Demographics\1.csv, clear
rename v1 School
rename v2 State
rename v3 PTD1516
rename v4 PTD1415
rename v5 PTD1314
rename v6 PTD1213
rename v7 PTD1112
rename v8 PTD1011
rename v9 PTD0910
rename v10 PTD0809
rename v11 PTD0708
rename v12 PTD0607
rename v13 PTD0506
rename v14 PTD0405
rename v15 PTD0304
rename v16 PTD0203
rename v17 PTD0102
rename v18 PTD0001
rename v19 PTD9900
rename v20 PTD9899
From v3 to v20, as you can see, the PTD (Pupil teacher ratio for Year 2015-2016, 2014-2015, etc) are the variables.
Is there a simpler way to use loops to rename all of the variables? I have hundreds of variables in my do-file, including many demographic variables (Grade 1 Hispanic Males in 1998-99, etc).
Thank you.
I am having troubles creating loops when naming variables.
I am using Stata/IC 15.1 for Windows.
When I uploaded the data into Stata from an NCES csv file, it named the variables v1, v2, v3, etc.
I had to rename these, so I did the following:
insheet using C:\Users\Mike\Desktop\Stata\Demographics\1.csv, clear
rename v1 School
rename v2 State
rename v3 PTD1516
rename v4 PTD1415
rename v5 PTD1314
rename v6 PTD1213
rename v7 PTD1112
rename v8 PTD1011
rename v9 PTD0910
rename v10 PTD0809
rename v11 PTD0708
rename v12 PTD0607
rename v13 PTD0506
rename v14 PTD0405
rename v15 PTD0304
rename v16 PTD0203
rename v17 PTD0102
rename v18 PTD0001
rename v19 PTD9900
rename v20 PTD9899
From v3 to v20, as you can see, the PTD (Pupil teacher ratio for Year 2015-2016, 2014-2015, etc) are the variables.
Is there a simpler way to use loops to rename all of the variables? I have hundreds of variables in my do-file, including many demographic variables (Grade 1 Hispanic Males in 1998-99, etc).
Thank you.
Comment