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 generate i*j by forvalues?If year=1,2,3,4; and prov=1,2,3,4,5,6,7. So how to calculate i*j, thanks a lot! I run this,but it is…
Place date year on a second line on x-axisMy x-axis data is currently in date (week) format, so my current code as part of a twoway graph is a…
collapse variable in more than 1 way in one collapse commandIs it possible to collapse the same variable in more than 1 way in 1 collapse command (e.g., to get …
xline and text on top of twoway area plotI use Code: twoway (area y1 y2 year) to create a plot and want to include a dashed vertical line on…
collapse variable in more than 1 way in one collapse commandIs it possible to collapse the same variable in more than 1 way in 1 collapse command (e.g., to get …
Subscribe to:
Post Comments (Atom)
0 Response to Using data labels previously stored after reshape command
Post a Comment