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

# Re: st: RE: constructing an unbalanced panel data set based on existing

 From n j cox To statalist@hsphsun2.harvard.edu Subject Re: st: RE: constructing an unbalanced panel data set based on existing Date Wed, 29 Mar 2006 17:29:33 +0100

```This example affords amusement at various levels.

First, only earlier today I posted

gen length = end - beg + 1
expand length
bysort Persnr beg: gen month = beg[1] + _n - 1
drop length

as an answer to a question to Anna Manzoni. In
its main feature, this is the same problem,
but no one seemed to notice.

Second, the laugh is also on me. Alex's elegant
solution underlines that my code was twice as
long as it should have been, as

expand end - beg + 1
bysort Persnr beg: gen month = beg[1] + _n - 1

would have been enough.

(That said, a composite id plus year variable
will not be the way to define a panel dataset.)

Nick
n.j.cox@durham.ac.uk

Ronnie Babigumira

> Im laughing at myself for what I posted before

Alex Ogan

> expand ((End - Start) + 1)
> bysort ID: gen IDyear = string(ID) + string(Start + _n - 1)

Arik

> I have a list of observations by unit (firm),
> which I would like to transfrom into a panle data set,
> by year/unit.
>
> Right now, the first variables of the observations
> look something like
>
> ID      Start      End      Industry
> 1       1985       1990        3
> 2       1988       1991        1
> 3       1982       1993        3
>
> And I'd like them to look like
>
> IDyear       Industry
> 11985            3
> 11986            3
> 11987            3
> 11988            3
> 11989            3
> 11990            3
> 21988            1
> 21989            1
> 21990            1
> 21991            1
> 31982            3
> 31983            3
> ...
> 31993            3
>
> Reshape does not seem to help, as I have a
> (unbalnaced) range, rather then a fixed list of
> variables. Any ideas, what I can do?
*
*   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–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index