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   "donsaane" <[email protected]>
To   <[email protected]>
Subject   RE: st: first -difference command
Date   Sat, 17 Sep 2011 11:02:32 -0400

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/


*
*   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