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: Deleting entire panel id/group if condition is true for first year


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Deleting entire panel id/group if condition is true for first year
Date   Wed, 1 May 2013 15:33:24 +0100

No need to apologise, but I guess I was responding to your last signal

nonmissing for the first year (or actually every year)

which I contracted to

nonmissing for every year

If you want to (mixing Stata and pseudocode)

by panel: keep if !missing(first value)

or

by panel: drop if missing(first value)

then the principle is similar. Here is an example you can try

webuse grunfeld
set seed 1052013
replace invest = . if runiform() < .1
bysort company (year) : drop if missing(invest[1])

We -drop-ped panels if and only of the first value of -invest- in each
was missing. The subscript was [1]. The subscript naturally depends on
the -sort- order, which is by -year- within -company-.

See also if needed

SJ-2-1  pr0004  . . . . . . . . . . Speaking Stata:  How to move step by: step
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q1/02   SJ 2(1):86--102                                  (no commands)
        explains the use of the by varlist : construct to tackle
        a variety of problems with group structure, ranging from
        simple calculations for each of several groups to more
        advanced manipulations that use the built-in _n and _N

http://www.stata-journal.com/sjpdf.html?articlenum=pr0004


Nick
[email protected]


On 1 May 2013 15:14, Andreas Dall Frøseth <[email protected]> wrote:
> Maybe I'm applying it wrong, but this does not seem to do that I want. I may have described it a bit to badly.
>
> So, here's an example.
> At this point my set is containing all companies with a run equal to or above 6 years. I identify these by using -tsspell- (SSC), and then "egen length = max(_seq), by(orgnr _spell)" (orgnr is the identifyer), and drop the unwanted companies by "drop if length<6"
> However, I also wish to drop entire panel groups (all six years for a company) if the variable "category" has a missing value the first year in the six year run. Leaving me with companies with runs equal to and above 7 years, in addition to companies with 6 year runs which have a value listed in the variable "category" the first year.
>
> I hope this was a better explanation. Pardon me in advance if the only reason that your previous code doesn't work is due to my incompetence...
>
> -Andreas
> ________________________________________
> Fra: [email protected] [[email protected]] p&#229; vegne av Nick Cox [[email protected]]
> Sendt: 1. mai 2013 15:34
> Til: [email protected]
> Emne: Re: st: Deleting entire panel id/group if condition is true for first year
>
> Stata makes this kind of change extremely easy.
>
> bysort id (whatever) : keep if !missing(whatever[_N]) & _N >= 6
>
> -sort-ing within panels means that any missings are sorted to last.
>
> This is covered in any tutorial on -by:-.
>
> Nick
> [email protected]
>
> On 1 May 2013 14:14, Andreas Dall Frøseth <[email protected]> wrote:
>>
>> Is it possible to delete a entire panel id/group from the set if a certain condition is true for the first year?
>> I'm trying to keep certain spells in my dataset, and by using the -tsspell- (SSC) I have managed to keep panel variables with runs equal or above 7 years. But, I also wish to keep panel groups with 6 year runs IF the value in the variable "category" is nonmissing for the first year (or actually every year).
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index