I have smallholder agriculture plot level commercialization data which i want to collapse to household level data. To avoid losing variable labels i resorted to the foreach loop method below by Cox;
Copy variable labels before collapse . foreach v of var * { . local l`v' : variable label `v' . if `"`l`v''"' == "" { . local l`v' "`v'" . } . } Attach the saved labels after collapse . foreach v of var * { . label var `v' "`l`v''" . }
Whenever i try running this codes, i am getting the error message:
"foreach command may not result from a macro expansion interactively or in do files"
What could be the reason? Thank you in advance
Takesure Tozooneyi
Related Posts with How to avoid losing variable labels when using collapse command
Subgroup analysis in stcoxDear Statalisters, In this first post on Statlist I apologize in advance if the format or details a…
ppml cluster - Gravity on product level with only one importerDear all I am evaluating the effect on american imports of the trade war dispute between China and …
Test of difference between meansHi, I have data where I have compared the means and from visualising it I can see that one group ha…
Exporting Tables from StataHello. I am currently writing my thesis and I have finished all my analysis. However, I am now strug…
Loop to create new variablesHello, I have data with a date variable and some other variables. For each date, there are multiple…
Subscribe to:
Post Comments (Atom)
0 Response to How to avoid losing variable labels when using collapse command
Post a Comment