Hello all:
I wrote a loop to calculate cumulative percentage of the categories in each year of several variables. I put
to tell Stata to skip the year if the variable is missing (see the simplified codes below. I removed most calculation part). This loop works well for some variables but not for some others. In the example below it works for DE_will but not for DE_income. The error message is
By -set trace- command I find -if !missing(`var')- does not recognize the case that DE_income is missing in 2000, and therefore the following -egen- command does not work. I checked these variables but did not find any reason. Can you figure it out? (It seems the example data file is too large to be uploaded. If you want to test the code, I can send you the data.)
I wrote a loop to calculate cumulative percentage of the categories in each year of several variables. I put
if !missing(`var')
r(111); __000001 not found
Code:
use example, clear foreach var of varlist DE_will DE_income { foreach n of numlist 2000 2003 2004 2005 2006 2007 2009 2011 2012 2013 { preserve keep if !missing(`var') & year==`n' if !missing(`var') { di `n' bysort `var': egen c_`var'=count(`var') restore } else { restore } } }
Comment