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: first -difference command


From   Austin Nichols <[email protected]>
To   [email protected]
Subject   Re: st: first -difference command
Date   Sun, 18 Sep 2011 07:38:17 -0400

My answer included this case; did you try the examples to understand
the import of my advice?
Though "mid the gap" was meant to read "mind the gap" meaning that if
there are gaps in your time series in any panel then x-x[_n-1] is NOT
the difference you want; you can check for that problem with
gen dx=x-x[_n-1] if year==year[_n-1]+3
or just use lag operators as I suggested.

On Sat, Sep 17, 2011 at 11:02 AM, donsaane <[email protected]> wrote:
> Thanks Austin,
>
> Maybe I was misunderstood. My panel dataset is sort by year, so I have :
> firmcode year
> 1        2006
> 1        2009
> 2        2006
> 2        2009
>
> I want to first-difference all my variables in order to be x[2006-2009]
> Can I just do: gen dx=x-x[_n-1]
>
> Thanks for the help
>
>
> -----Message d'origine-----
> De : [email protected]
> [mailto:[email protected]] De la part de Austin Nichols
> Envoyé : vendredi 16 septembre 2011 12:29
> À : [email protected]
> Objet : Re: st: first -difference command
>
> donsaane dontsi <[email protected]> :
> Not necessarily;mid the gap.  If you have no missing years, you can
> use a lag operator:
>
> clear
> range year 2006 2012 3
> g x=uniform()
> tsset year, delta(3)
> g d=x-L.x
> *or if you want to do it by hand you can
> gen dx=x-x[_n-1] if year==year[_n-1]+3
> list
>
> *With panel data, you can do almost the same thing:
>
> expand 10
> bys year: g i=_n
> g u=uniform()
> tsset i year, delta(3)
> g du=u-L.u
> bys i (year): g du2=x-u[_n-1] if year==year[_n-1]+3
> list, sepby(i) noo
>
> * but beware of missing values in time variables (which I have
> mentioned a couple times at Stata meetings, but not on Statalist):
> g badt=year if i<5
> tsset i badt
> g bad=u-L.u
> sort u
> tsset i badt
> g worse=u-L.u
> list
>
> On Fri, Sep 16, 2011 at 11:52 AM, donsaane dontsi <[email protected]> wrote:
>> Hi ,
>>
>> I would like to run a first -difference method. I have a
>> dataset of two years : 2006-2009. To transform all my variables into
> difference
>> variables , does this command work for 2006 and 2009 : gen dx = x[_n]-
> x[_n-1]
>> ?

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index