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
Does VIF account for negative correlations?Does VIF account for inverse correlation? For example if you have two variables that are negatively …
How to use different instruments for different equations when implementing 3SLS estimation procedure for simultaneous equations?I am using reg3 command to estimate simultaneous equations, it looks the same instrumental variables…
Installing combineplot manuallyHello there, Grateful is someone could post on where I can locate the ado files for "combineplot". …
Adding a label to the last observation on a line chartI'm pretty sure I've seen this here before, but I can't seem to find the post. I'm interested in add…
Unexpected behavior with in-line if statementsI experienced a quirk with Stata. It appears that if statements read (and evaluate) the entire line,…
Subscribe to:
Post Comments (Atom)
0 Response to Using data labels previously stored after reshape command
Post a Comment