I am currently cleaning survey data that contains 1000+ variables many of which need to be renamed because they are inappropriately numbered.
For example some of the variables in the dataset are (changed names for anonymity)
pt1surveyoption_1_2_1
pt1surveyoption_1_2_2
pt1surveyoption_1_2_3
pt1surveyoption_1_2_4
pt1surveyoption_2_2_1
pt1surveyoption_2_2_2
pt1surveyoption_2_2_3
pt1surveyoption_2_2_4
pt2surveyoption_1_2_1
pt2surveyoption_1_2_2
pt2surveyoption_1_2_3
pt2surveyoption_1_2_4
pt2surveyoption_2_2_1
pt2surveyoption_2_2_2
pt2surveyoption_2_2_3
pt2surveyoption_2_2_4
For reshaping the data accurately Where _#_#_# means _optionnumber_individualnumber_groupnumber
pt1surveyoption_1_1_2
pt1surveyoption_2_1_2
pt1surveyoption_3_1_2
pt1surveyoption_4_1_2
pt1surveyoption_1_2_2
pt1surveyoption_2_2_2
pt1surveyoption_3_2_2
pt1surveyoption_4_2_2
pt2surveyoption_1_1_2
pt2surveyoption_2_1_2
pt2surveyoption_3_1_2
pt2surveyoption_4_1_2
pt2surveyoption_1_2_2
pt2surveyoption_2_2_2
pt2surveyoption_3_2_2
pt2surveyoption_4_2_2
The goal is to have a loop where I will search through varlist _all and pick out varnames which correspond to the _#_#_# format (because many do not) and then reorder it so that way the last number gets bumped to the front as you can see above. I have tried to has() function but I do not know how to specify that format to make a patternlist and do not know how to use said function to make a list to of variables. Any help or direction to a similar solved problem would be much appreciated thank you.
Related Posts with Bulk reordering the name of variable conditional on it's format
Error in expressionHello, I am created a local variable `tif' which loops over around 45 terms (string). local tif "0…
Problem with two merged datasets: time series and panel data relatedHi all, I am new to statalist, and relatively new to stata, so please bear that in mind when replyin…
Gen new variableHi! I want to make a measure for institutional trust. x1 = trust in judicial system x2 = trust in …
Graph: Large gap between xlabel and legendHi I am trying to make a graph similar to this one: Code: sysuse auto, clear gen xvar = _n keep if…
net reclassification index (NRI) and integrated discrimination index (IDI)*computing confidence intervalsHi All, I am having difficulties obtaining 95% CI's from the NRI and IDI command in stata. I have p…
Subscribe to:
Post Comments (Atom)
0 Response to Bulk reordering the name of variable conditional on it's format
Post a Comment