Dear Statalisters,
I am using Stata 16 and working with the following dataset:
input byte Bank str114 Item double(v_01_04_2007 v_01_05_2007 v_01_06_2007 v_01_07_2007 v_01_08_2007 v_01_09_2007)
1 "Cash (1000)" . . . . . .
1 "Securities (1200)" . . . . . .
2 "Cash (1000)" 655044 713733 684172 776261 938589 702173
2 "Securities (1200)" 0 0 0 0 0 0
3 "Cash (1000)" 16760166 21476115 21900576 24115883 29332837 28871567
3 "Securities (1200)" 182416966 222171729 221152928 213929525 179653937 168143292
All variables are reported under the same column (Item) and months appear under columns (v_01_04_2007 v_01_05_2007 etc.). I need to reshape the data. Variable names are stored under "Item". I am trying to have each separate variable in columns using the following code:
reshape long v_, i(Item Bank) j(year) string
levelsof Item, local(VarLab)
egen group_var=group(Item)
drop Item
reshape wide v_, i(Bank year) j(group_var)
foreach i of local VarLab {
foreach j in v_1-v_133 {
la var `j' "`i'"
}
}
The last part of my code, the foreach loops, is to assign the previously stored variable names (in the local variable VarLab) as a label to each variable. Ideally I could also rename the variables but, since there are blanks and special characters in the variable names, I thought it good to use this shortcut. Unfortunately I am able to assign the correct label just to the first variable.
I would really appreciate your help.
Davide
Related Posts with Using data labels previously stored after reshape command
How to use append in esttabHi everyone I am using the following dataset and creating 2 tables Code: * Example generated by -da…
Levene’s testDear researchers, I have unbalanced panel data for more than 200 firms for the period that extend fr…
How to save 1 specific xtreg beta coefficient to use in postestimations?Dear Stata Community members, I would like to ask how I can save one particular beta coefficient af…
Choosing the best model- Panel data regression analysisHi, I am new in this forum, I read many useful comments related to panel data analysis. I am from fi…
Update to -overid- available on SSCWith thanks as usual to Kit Baum, an update to our program overid is now available on SSC. overid i…
Subscribe to:
Post Comments (Atom)
0 Response to Using data labels previously stored after reshape command
Post a Comment