Statalist


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

RE: AW: st: Eliminating patterns from Panel Data


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: AW: st: Eliminating patterns from Panel Data
Date   Sun, 20 Jan 2008 17:12:21 -0000

A couple of details in addition to Maarten's very helpful post: 

This program lacks a -version- statement. 

It will, I think, work in Stata 9 or 10. The use of -levelsof- means
that it would not work in Stata 8 or earlier. Changing -levelsof- to
-levels- would be a fix for (updated) Stata 8. 

Nick 
[email protected] 

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Maarten buis
Sent: 19 January 2008 22:48
To: [email protected]
Subject: Re: AW: st: Eliminating patterns from Panel Data

--- 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------------------



*
*   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