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]
Re: st: onespell
"Fabian Schönenberger" <email@example.com>
Re: st: onespell
Tue, 04 Sep 2012 15:45:22 +0200
Many thanks, Nick. With those commands I am able to resolve the sample from gaps, and keep the longest and most recent spells.
-------- Original-Nachricht --------
> Datum: Tue, 4 Sep 2012 11:21:08 +0100
> Von: Nick Cox <firstname.lastname@example.org>
> An: email@example.com
> Betreff: Re: st: onespell
> -onespell- uses -tsspell- (SSC), which you will have downloaded. The
> use of -tsfill- within -onespell- is not optional, so you can fall
> back on -tsspell- and some data management.
> Let's suppose that the time variable is -fyear- as in your question
> and that you have panel identifier -id- and have
> tsset id fyear
> tsspell, f(L.fyear == .)
> identifies spells of contiguous observations. See the help or
> FAQ . . . . . . Identifying runs of consecutive observations in panel
> . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox and V.
> 8/02 How do I identify runs of consecutive observations
> in panel data?
> The longest such spell can be identified by calculating in turn the
> length of each spell
> egen length = max(_seq), by(id _spell)
> and then the longest for each panel
> egen maxlength = max(length), by(id)
> so that
> keep if length == maxlength
> would keep the longest spell. However, two or more spells could be of
> the same length for any -id-. If so, all are retained. You would need
> another rule for selecting which. For example
> bysort id (_spell) : keep if _spell == _spell
> keeps the first such spell, and
> bysort id (_spell) : keep if _spell == _spell[_N]
> keeps the last.
> Warning: all code untested.
> On Tue, Sep 4, 2012 at 10:48 AM, "Fabian Schönenberger" <firstname.lastname@example.org>
> > Dear Statalist
> > I am using onespell, SSC stata modul from Christopher F. Baum, for panel
> data. I write:
> > onespell fyear,saving(test)
> > Observations removed: -18332
> > file test.dta saved
> > fyear is a time variable (annual). For certain id, fyear has gaps if for
> instance the company stopped generating annual reports and started again
> after some years passed. I expected onespell to keep only the longest
> contiguous spells of fyear for each id, and other observations will be deleted
> from the file. But onespell adds new rows filling the gaps of fyear. In my
> case, onespell adds 18332 new observations (all observations except from
> fyear are missing).
> > How can I keep the longest contiguous spells for fyear for each id and
> drop the other observations?
> * 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/
* For searches and help try: