i have several variables that i want to rename according to their category for example S2_Q1P- S2_Q7P would be plot and i want to rename them in a sequence such that the result is S2_Q1P_1- S2_Q7P_9.. I use the following code and i get the message
1 new variable name invalid
You attempted to rename S2_Q1K to 1. That is an invalid Stata variable name.
forval i=1/9 {
rename S2_Q1K `i' S2_Q1P `i' S2_Q1D `i'
rename S2_Q2AK`i' S2_Q2AP`i' S2_Q2AD`i'
rename S2_Q2BK`i' S2_Q2BP`i' S2_Q2BD`i'
rename S2_Q3AK`i' S2_Q3AP`i' S2_Q3AD`i'
rename S2_Q3BK `i' S2_Q3BP `i' S2_Q3BD `i'
rename S2_Q4K `i' S2_Q4P `i' S2_Q4D `i'
rename S2_Q5K `i' S2_Q5P `i' S2_Q5D `i'
rename S2_Q6K `i' S2_Q6P `i' S2_Q6D `i'
rename S2_Q7K `i' S2_Q7P `i' S2_Q7D `i'
}
i am renaming then in order to reshape such that corresponding questions align with the category name. should i use foreach v in varlist instead but how would i rename all of them in the simplest way possible? or is it not necessary for me to rename at all? I am very confused, earlier i had used forval i=1/9 to rename S2_Q2_01 and it had worked at that time. thank you for all the help i really appreciate it.
Related Posts with renaming several variables in loop to reshape by category
Area Under Curve (AUC) after random Effects modelsI would like to know how can I calculate AUC after I run a logit model using runmlwin command throug…
Collapse says varlist requiredHi! I tried to collapse the following data but it says varlist required, why? collapse smi1 smi2 l…
Displaying number of observations after "Repest" commandI use the user written command "Repest" to analyse PISA survey data. I then use eststo and esttab to…
State-level time series: tool for calculating requisite number of observations per state/year?Greetings, I'm running Stata 15.1 on OSX. My ultimate goal is to examine whether changes in a speci…
line of fit for two skewed continuous variablesI am conducting Spearman's correlation on two skewed continuous variables. I do not wish to log tran…
Subscribe to:
Post Comments (Atom)
0 Response to renaming several variables in loop to reshape by category
Post a Comment