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
Fri, 16 Sep 2011 12:28:52 -0400
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/