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 at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: calculating differences in variables in Longitudinal Data


From   Abhimanyu Arora <abhimanyu.arora1987@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: calculating differences in variables in Longitudinal Data
Date   Mon, 9 Apr 2012 21:36:08 +0200

Hi

I would do it as follows

tsset year
forvalues i=1/54{
gen diff`i'=.
bys company:replace diff`i'=S2.var`i' if year==2011
}

Cheers
Abhimanyu

On Mon, Apr 9, 2012 at 9:23 PM, Alexander Zoran Dozet <zod_63@yahoo.se> wrote:
>
> Dear Statausers,
>
> I have a small problem
> that I suppose is easy to resolve if one knows the ansewer. Although it
> probably is basic, I have tried to solve it by searching the internet
> and hitting the books, I have not succeded in finding an answer.
>
> I have a dataset that looks like this:
>
>
> Company                Year                    Variable1                Variable2                Variable3.........Variable54
>
> Company1              2009                    60                            70                           80
> Company1              2010                    65                            72                           81
>
> Company1              2011                    67                            71                           85
>
> Company2              2009                    85                            80                           70
>
> Company2              2010                    75                            85                           78
>
> Company2              2011                    77                            88                           76
>
> .
> .
> .
> Company154
>
>
> I hope the displayed data structure is kept in this e-mail.
> Each company is occuring one time each year for each variable in the data
> set (panel data). My variable Company is in string form. I have not
> declared my dataset to be panel data. String is not allowed as an
> identifier.
>
> I want to examine the difference between the
> year 2010 and 2011 for each company and for each variable and to create a new variable for each of the differences for
> example diffVar1, diffVar2,....
>
> I would be much grateful for any help!
>
> Best regards and cheers
> Alexander Dozet
>
> *
> *   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