Hello all
I am using a multiyear survey dataset and tabout user written command (written by Ian watson) to export results.
I am frequently running into the problem where the loop fails and says "no observation in subpop() subpopulation" r(461). I have attached the screenshot for this thread.
As the loop was failing multiple times, I tried to use the if else command as follows
count if (CASE_SURGERY_ANY_DX ==1 & CASE_`h'_PRI ==1 & YEAR==`l' )
if `r(N)' >0 {
tabout command
}
else {
di "no subpopulation"
}
However the loop is still failing and I am not sure how to rectify it.
I was hoping to see if any of the stata experts can help me.
I have posted the code and screenshot as attachment
Thank you,
Praveen
I am using a multiyear survey dataset and tabout user written command (written by Ian watson) to export results.
I am frequently running into the problem where the loop fails and says "no observation in subpop() subpopulation" r(461). I have attached the screenshot for this thread.
As the loop was failing multiple times, I tried to use the if else command as follows
count if (CASE_SURGERY_ANY_DX ==1 & CASE_`h'_PRI ==1 & YEAR==`l' )
if `r(N)' >0 {
tabout command
}
else {
di "no subpopulation"
}
However the loop is still failing and I am not sure how to rectify it.
I was hoping to see if any of the stata experts can help me.
I have posted the code and screenshot as attachment
Thank you,
Praveen
Code:
capture log close log using "surgery.log", replace foreach h in MALIG BEN { qui use YEAR KEY CASE_PRO_MULTI_PRI /// CASE_`h'_PRI CASE_SURGERY_ANY_DX using "Z:/surgery_2007.dta", clear forvalues i=2008/2011{ append using "Z:/surgery_`i'.dta" , keep(YEAR KEY CASE_PRO_MULTI_PRI CASE_`h'_PRI CASE_SURGERY_ANY_DX) } forvalues i=2007/2011{ merge 1:1 KEY using "Z:/NIS_CORE_DESIGN_`i'.dta",keepusing(KEY DISCWT HOSPID NIS_STRATUM YEAR) update drop _merge merge 1:1 KEY using "Z:/NIS_CORE_ANALYSIS1_`i'.dta", keepusing(KEY FEMALE PAY1 RACE ELIXHAUSER_CAT) update drop _merge } * SVYSET THE POPULATON svyset [pweight= DISCWT ],strata (NIS_STRATUM ) psu( HOSPID ) * setup macros for loops levelsof YEAR , local(levels) local YEARlabels : value label YEAR local counter = 0 local filemethod = "replace" local heading = "" * begin looping through the values of the by category foreach l of local levels { count if (CASE_SURGERY_ANY_DX ==1 & CASE_`h'_PRI ==1 & YEAR==`l' ) if `r(N)' >0 { if `counter' > 0 { local filemethod = "append" local heading = "h1(nil) h2(nil)" } local vlabel : label `YEARlabels' `l' tabout FEMALE RACE PAY1 ELIXHAUSER_CAT CASE_PRO_MULTI_PRI if YEAR == `l' & (CASE_SURGERY_ANY_DX ==1 & CASE_`h'_PRI ==1 ) using /// "C:/data/`h'_count_3.xls", `filemethod' `heading' h3("YEAR: `vlabel'") c(freq ) f(0c 1 ) svy mi local counter = `counter' + 1 } else { di "no subpopulation" } } } *
Comment