Statalist


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

Re: st: Code erroring out because of "no observations"


From   Scott Merryman <scott.merryman@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Code erroring out because of "no observations"
Date   Thu, 25 Jun 2009 16:06:59 -0500

Perhaps, something like this:


webuse nlswork, clear

sort idcode year
bysort idcode: egen wave = seq()

tsset idcode wave

gen pred_wave =.
logit union age collgrad tenure hours if wave==1

predict pred if e(sample)
replace pred_wave = pred
drop pred

levelsof wave if wave >1, local(levels)
foreach i of local levels {
	qui {
		logit  union  l.ln_wage l.age l.collgrad l.tenure l.hours if wave==`i'
		predict pred if wave == `i'
		replace pred_wave= pred if wave == `i'
		drop pred
	}
}

keep pred wave idc
reshape wide pred, j(wave) i(idco)
egen predfinal = rowmax( pred*)


Scott
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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