Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fwd: st: how to keep labels when using foreach
From
anne broe <[email protected]>
To
[email protected]
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)
`val'
}
if substr("`xx'",1,3)=="BMI" {
local val=substr("`xx'", -1,1)
local label:label(BMI)
`val'
}
if substr("`xx'",1,9)=="education" {
local val=substr("`xx'", -1,1)
local label:label(education)
`val'
}
if substr("`xx'",1,7)=="smoking" {
local val=substr("`xx'", -1,1)
local label:label(smoking_status)
`val'
}
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:
m_agegr==0
(xxxx observations deleted)
Duplicates in terms of newpnr
(xx observations deleted)
(xx missing values generated)
(x missing values generated)
invalid syntax
r(198);
Since I cant find the error in the do file, maybe someone else can help me :)
Thanks
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/