--- Maarten buis <[email protected]> wrote:
> I am not particularly interested in making this program more
> generally available (e.g. through -ssc-), eventhough that is now
> trivially easy. The reason is that I don't think that this command is
> very useful. This way you can easily end up ignoring 90% or more of
> your data. All I wanted to show is that if you want a command you can
> easily make one yourself.
The example below illustrates that point. In the case of nlswork only
1.8% of all respondents was observed in all waves! So using only
complete units would discard 98.2% of all respondents. That does not
seem wise.
For the example to work you need to make the command -mkbalanced-
available as described in:
http://www.stata.com/statalist/archive/2008-01/msg00511.html
At the bottom I have added an update with with a version statement as
sugested by Nick and I also added a variable label for the generated
variable.
*----------- begin example -----------------
webuse nlswork, clear
mkbalanced, gen(balanced)
bys idcode (year) : gen first = _n == 1
sum balanced if first
*------------ end example ------------------
*--------- begin mkbalanced.ado------------------
*! version 1.0.2 MLB 20Jan2008
program define mkbalanced, sortpreserve
version 9.1
syntax, GENerate(name)
confirm new var `generate'
capture xtset
if _rc == 459 {
di as err ///
"panel variable not set, use -xtset varname ...-"
}
local panelvar "`r(panelvar)'"
local timevar "`r(timevar)'"
tempvar touse nvals
gen byte `touse' = !missing(`timevar')
qui levelsof `timevar'
local t : word count `r(levels)'
bys `panelvar' `timevar' `touse' : ///
gen long `nvals' = _n == 1 if `touse'
bys `panelvar' `touse' : ///
replace `nvals' = sum(`nvals') if `touse'
bys `panelvar' `touse' : ///
gen byte `generate' = `nvals'[_N]== `t'
label variable `generate' ///
"whether or not a unit is completely observed"
end
*--------- end mkbalanced.ado------------------
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
__________________________________________________________
Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/