Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: In unbalanced panel, make sure individuals begin in month X and end in month Y


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: In unbalanced panel, make sure individuals begin in month X and end in month Y
Date   Sat, 8 Oct 2011 23:08:29 +0100

What's wrong with an -if- condition?

Nick

On Sat, Oct 8, 2011 at 9:59 PM, Richard Herron
<[email protected]> wrote:
> How can I make sure individuals in a panel begin in one given month
> and ends in another given month? For example, I want to make sure that
> every firm in an unbalanced monthly panel begins in April and ends in
> March. A priori I don't know each firm's first or last month (i.e.,
> unbalanced panel).
>
> My end goal is to use -rolling- to perform regressions with a 48-month
> window and a 12-month step size to get regression coefficients each
> year. I want to avoid regressing every month and dropping 11 of 12
> entries each year, which would be very time-consuming.
>
> Thanks! Here is some code:
>
> * ----- begin code -----
> * generate random starting dates
> clear
> set obs 250
> egen int id = seq()
> generate int date_m = 1 + int(12*runiform())
> generate int date_y = 1960 + int(50*runiform())
> generate int date_ym = ym(date_y, date_m)
> format date_ym %tm
>
> * add random number of observations to each id
> generate int n_obs = 1 + int(20*12*runiform())
> expand n_obs
> bysort id: replace date_ym = date_ym + _n
>
> * generate random variables
> generate y = rnormal()
> generate x = rnormal()
>
> * I would like to do this rolling regression with a 12 month step-size
> * and have them go from April through March four years later
> tsset id date_ym
> rolling z = (e(rss) / e(N)) ///
>    , window(48) stepsize(12) saving(temp, replace) ///
>    : regress y x
>
>  * ----- end code -----
> *

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index