[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:25:37 +0000 (GMT)

--- Martin Weiss <[email protected]> wrote:

> Thanks Maarten for the immediate reply, StataCorp might wanna
> consider adding a command for this problem... Could be something like
> the "duplicates"-handling...

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. You can store
the section between 

*--- begin mkbalanced.ado--- and 
*---- end mkbalanced.ado---- 

in a separate file called mkbalanced.ado and store it in your personal
directory along your adopath (type in Stata -personal- to see where
that directory is on your computer). In the same directory store the
section between:

*--- begin mkbalanced.hlp--- and 
*---- end mkbalanced.hlp---- 

in a separate file called mkbalanced.hlp.

After that -mkbalanced- will be available to your as any other Stata

*--------- begin mkbalanced.ado------------------
*! version 1.0.0 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 
	gen byte `touse' = !missing(`timevar')

	qui levelsof `timevar'
	local t : word count `r(levels)'
	bys `panelvar' `touse' : ///
          gen byte `generate' = _N == `t' if `touse'
*--------- end mkbalanced.ado------------------

*----------------- begin mkbalanced.hlp ---------------------
{* 19Jan2008}
help for {hi:mkbalanced}


{p2colset 5 19 21 2}{...}
{p2col :{hi: mkbalanced} {hline 2}}Creates a variable marking complete


{p 8 15 2}
{cmd:mkbalanced} {cmd:,} {opt gen:erate(newvarname)} 


{cmd:mkbalanaced} creates a new variable that marks whether a unit is 
observed in during all instances of {it:timevar}, as set in {help
xtset}. For this reason the data must be {cmd: xtset}.


{opt gen:erate(newvarname)} Specifies the variable name of the variable
that will mark complete panels.


{phang}{cmd:. webuse nlswork, clear} {p_end}
{phang}{cmd:. mkbalanced, gen(balanced) } {p_end}
{phang}{cmd:. xtreg ln_w union if balanced}


{p 4 4}
Maarten L. Buis{break}
Vrije Universiteit Amsterdam{break}
Department of Social Research Methodology{break}
[email protected] 

{title:Also see}

Online:  {helpb xtset} {helpb xtdescribe}
*----------------- end mkbalanced.hlp ---------------------

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

Support the World Aids Awareness campaign this month with Yahoo! For Good
*   For searches and help try:

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