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
building a categorial variable based on confidence intervallsDear all, I try to part a continous variable in categories using the 50% CI. Literture ref: "The a…
starting values in mixedlogitDear All, I am analyzing a DCE to estimate WTP values for environmental protection and I am trying d…
MCHANGE after GSEMHello statalisters, I am trying to estimate the marginal effects after a gsem command but am unsure…
How to generate a variable with with fixed correlations to an existing variable which already has a uniform distributionHi, I have generate a variable which I have called X, it has a uniform distribution like this: gen x…
building a categorial variable based on confidence intervallsDear all, I try to part a continous variable in categories using the 50% CI for age groups. Litert…
Subscribe to:
Post Comments (Atom)
0 Response to Bulk reordering the name of variable conditional on it's format
Post a Comment