0
votes

I want to keep my variable labels after collapsing in stata. I found Nick Cox's solution not working for me. The code looks like this: Before -collapse-, copy the variable labels to local macros:

foreach v of var * { 
    local l`v' : variable label `v' 
} 

After -collapse-, use the old labels:

foreach v of var * { 
    label var `v' "`l`v''" 
} 

All my variables after collapsing still have no labels.

1
please accept the answer, as the syntax does what you asked for.eborbath

1 Answers

-1
votes

This post extensively tackles the problem, but:

before collapse you need:

foreach v of var * {
 local l`v' : variable label `v'
       if `"`l`v''"' == "" {
    local l`v' "`v'"
    }
}

after collapse you need:

foreach v of var * {
label var `v' "`l`v''"
}