Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: AW: st: Eliminating patterns from Panel Data


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: AW: st: Eliminating patterns from Panel Data
Date   Sat, 19 Jan 2008 22:48:16 +0000 (GMT)

--- Maarten buis <[email protected]> wrote:
> No need to wait for StataCorp. One of the nice things about Stata is
> that you can do it yourself, like in the example below. 

Here is a small update that should be a bit safer (it now uses some
tricks from http://www.stata.com/support/faqs/data/distinct.html )

*--------- begin mkbalanced.ado------------------
*! version 1.0.1 MLB 19Jan2008
program define mkbalanced, sortpreserve
	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'
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/
-----------------------------------------


      ___________________________________________________________
Support the World Aids Awareness campaign this month with Yahoo! For Good http://uk.promotions.yahoo.com/forgood/
*
*   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/



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