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]

From |
"donsaane" <donsaane@yahoo.fr> |

To |
<statalist@hsphsun2.harvard.edu> |

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 : owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] De la part de Austin Nichols Envoyé : vendredi 16 septembre 2011 12:29 À : statalist@hsphsun2.harvard.edu Objet : Re: st: first -difference command donsaane dontsi <donsaane@yahoo.fr> : 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 <donsaane@yahoo.fr> 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/

**Follow-Ups**:**Re: st: first -difference command***From:*Austin Nichols <austinnichols@gmail.com>

**References**:**st: first -difference command***From:*donsaane dontsi <donsaane@yahoo.fr>

**Re: st: first -difference command***From:*Austin Nichols <austinnichols@gmail.com>

- Prev by Date:
**Re: st: Comparing coefficients from two ivregress models** - Next by Date:
**Re: st: Comparing coefficients from two ivregress models** - Previous by thread:
**Re: st: first -difference command** - Next by thread:
**Re: st: first -difference command** - Index(es):