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