Bookmark and Share

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]

RE: st: RE: first-difference command


From   "Sarah Edgington" <sedging@ucla.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: first-difference command
Date   Fri, 16 Sep 2011 13:33:43 -0700

.
If you do bysort firmcode: gen dx = x-x[_n-1] missing values will be
generated for all the 2006 firms because there is no previous observation
for them.  I think this is what you want to happen.  If you simply gen dx =
x-x[_n-1] the result for the 2006 observation for firm 2 will be the value
of x in 2006 in firm 2 minus the value of x in 2009 for firm 1 (because
that's the previous observation).  This is almost certainly not a desired
outcome.

-Sarah

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of donsaane dontsi
Sent: Friday, September 16, 2011 1:05 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re : st: RE: first-difference command

 When I use this command: bys firmcode: gen dx = x-x[_n-1], I have 75
missing values generated, although when I use: gen dx=x-x[_n-1], I have only
one missing values generated. I' m wondering if I could just use the last
command. 

Thanks 
 
dsd


----- Mail original -----
De : Mauro Mastrogiacomo <M.Mastrogiacomo@cpb.nl> À :
"'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> Cc : 
Envoyé le : Vendredi 16 Septembre 2011 15h40 Objet : st: RE:
first-difference command

Sorry I missed your original message but I suppose you want to code:
bys firmcode: gen dx = x-x[_n-1]

another option could be:
xtset firmcode year
gen dx=D.x

mauro


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of donsaane dontsi
Sent: vrijdag 16 september 2011 21:27
To: statalist@hsphsun2.harvard.edu
Subject: st: first-difference command

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

 
dsd

*
*   For searches and help try:
*  http://www.stata.com/help.cgi?searchhttp://www.stata.com/support/statalist/faqhttp://www.ats.ucla.edu/stat/stata/

--
============================================================================
====
Dit bericht kan informatie bevatten die niet voor u is bestemd. Indien u
niet de geadresseerde bent of dit bericht abusievelijk aan u is toegezonden,
wordt u verzocht dat aan de afzender te melden en het bericht te
verwijderen.
De Staat aanvaardt geen aansprakelijkheid voor schade, van welke aard ook,
die verband houdt met risico's verbonden aan het elektronisch verzenden van
berichten.

This message may contain information that is not intended for you. If you
are not the addressee or if this message was sent to you by mistake, you are
requested to inform the sender and delete the message. The State accepts no
liability for damage of any kind resulting from the risks inherent in the
electronic transmission of messages.
============================================================================
====

*
*   For searches and help try:
*  http://www.stata.com/help.cgi?searchhttp://www.stata.com/support/statalist/faqhttp://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/


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