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
How do I visualize the relationship between a continuous and a ordinal variable?Hi, I would like to create a scatterplot including a linear regression line. The x-axis should be o…
Can I use logit without with YES/NO data instead of 0/1?Hi, everyone, All my data are in YES/NO values instead of 0/1. And I want to find the correlation a…
Construct equally weighted decile portfolios by ranking stocks on past 3 years volatilityHey dear Members, I have a data sets of about 303 companies with monthly returns of the last 22 yea…
Proper titles for outreg2 output tableDear Stata users, I am trying to export summary statistics using outreg2 function with the followin…
Question regarding Wilcoxon signed-rank tests for weighed dataI am using sample weighted data. I want to compare a result before and after an intervention. I woul…
Subscribe to:
Post Comments (Atom)
0 Response to Bulk reordering the name of variable conditional on it's format
Post a Comment