Statalist


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

st: RE: RE: Re: percent of time a


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Re: percent of time a
Date   Wed, 11 Feb 2009 20:40:37 -0000

I've not tried understanding this but my guess is that -collapse- on an
indicator and whatever -by()- you want would get you there with less
pain. 

Nick 
[email protected] 

Howard Lempel

It would have been helpful if I'd been more explicit.  I have various
income variables that are topcoded and censored at zero and would like
to know how often that bites among many different subpopulations.  The
censoring means that p(X_i=0) is not zero.  I guess it's also true that
my variables are not strictly continuous in that they're rounded to the
nearest integer.

I ended up doing something like the following:

Gen zero = .
foreach var in `vars' {
	local rowcount = 1
	foreach gend in `genders' {
		foreach yr in `yrs' {
			local colcount = 1
			*Do other things
			. . .
			. . .
			*Find out how often my variable is zero		
			replace zero = (`var'==0)
			sum zero [aw=wgt] if gender==`gend' &
year==`yr', meanonly
			matrix `var'mat[`rowcount', `colcount'] =
r(mean)
			local colcount = `colcount' + 1
			*Do more other things
			. . . 
			. . .
			}
		}
	}

Nick's method using the _gwtmean function for -egen- also works, but
since there's no -ereplace- function, it would have involved either
-dropping- a variable in each iteration of the loop, or -egenerating-
lots of variables.


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index