Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: st: how to keep labels when using foreach

From   anne broe <>
Subject   Fwd: st: how to keep labels when using foreach
Date   Wed, 13 Mar 2013 12:59:28 +0000

I have a few more variables than the two first posted.
When I apply Nicks suggestion to my do file the following happens:

foreach xx in m_agegr==0 m_agegr==15 m_agegr==20 m_agegr==25
m_agegr==30 m_agegr==35 m_agegr==40 m_agegr==45         ///
            BMI==0 BMI==18 BMI==25 BMI==30 BMI==35 BMI==40 education==1    ///
            education==2 education==3 education==0 smoking_status==0
smoking_status==1 smoking_status==2 smoking_status==3    {
        use Work\Temp4, clear
        display "`xx'"
        keep if `xx'
        duplicates drop newpnr, force
        gen atc_yes = 1 if ga_atc==1
        gen atc_no = 1 if ga_atc==0
        if substr("`xx'",1,7)=="m_agegr" {
            local val=substr("`xx'", -1,1)
            local label:label(m_agegr)
        if substr("`xx'",1,3)=="BMI" {
            local val=substr("`xx'", -1,1)
            local label:label(BMI)
        if substr("`xx'",1,9)=="education" {
            local val=substr("`xx'", -1,1)
            local label:label(education)
        if substr("`xx'",1,7)=="smoking" {
            local val=substr("`xx'", -1,1)
            local label:label(smoking_status)
        collapse (sum) atc_yes atc_no
        gen str30 group=
        label var group "`l`v''"
        if "`xx'" != "m_agegr==0" append using Work\Q4
    save Work\Q4, replace

This is the error message i get:

(xxxx observations deleted)

Duplicates in terms of newpnr

(xx observations deleted)
(xx missing values generated)
(x missing values generated)
invalid syntax

Since I cant find the error in the do file, maybe someone else can help me :)

*   For searches and help try:

© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index