Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

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


From   Richard Herron <richard.c.herron@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: In unbalanced panel, make sure individuals begin in month X and end in month Y
Date   Sat, 8 Oct 2011 16:59:35 -0400

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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index