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
Issues with HHI creationHi, I am new to the forum and to stata as well. I know this topic has been covered multiple times b…
Rename a function?How should I rename a function in Stata? I combine Stata and R, and to reduce confusion, I’d like t…
Multilevel regression and/or clustering standard errorsHello, In case of multilevel data, it is obvious to use for example - mixed -, but using - mixed - …
Stata job opportunity in Cmabridge MA NBER has an opening for a "professional to work with researchers to explore, procure, & curate …
Testing means with missing valuesHello everyone, I have a small problem executing a one-would-think simple t-test and I hope you can…
Subscribe to:
Post Comments (Atom)
0 Response to Bulk reordering the name of variable conditional on it's format
Post a Comment