Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

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 <richard.c.herron@gmail.com> 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/

**Follow-Ups**:**Re: st: In unbalanced panel, make sure individuals begin in month X and end in month Y***From:*Richard Herron <richard.c.herron@gmail.com>

**References**:**st: In unbalanced panel, make sure individuals begin in month X and end in month Y***From:*Richard Herron <richard.c.herron@gmail.com>

- Prev by Date:
**Re: st: how to put both coefficient and exponentiated form in a table using estout or similar command** - Next by Date:
**st: correct syntax for xtdpdsys** - Previous by thread:
**st: In unbalanced panel, make sure individuals begin in month X and end in month Y** - Next by thread:
**Re: st: In unbalanced panel, make sure individuals begin in month X and end in month Y** - Index(es):