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: create a variable using the first value in time-series data by group


From   Sergiy Radyakin <serjradyakin@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: create a variable using the first value in time-series data by group
Date   Mon, 10 Jun 2013 22:00:45 -0400

Once you have the first value figured out, something like this would
populate the rest:

clear
input id year x
1 2000 0.7
1 2001 .
1 2002 .
1 2003 .
2 2000 0.9
2 2001 .
2 2002 .
2 2003 .
end
bysort id (year): replace x=x[1]
list, sepby(id)

     +----------------+
     | id   year    x |
     |----------------|
  1. |  1   2000   .7 |
  2. |  1   2001   .7 |
  3. |  1   2002   .7 |
  4. |  1   2003   .7 |
     |----------------|
  5. |  2   2000   .9 |
  6. |  2   2001   .9 |
  7. |  2   2002   .9 |
  8. |  2   2003   .9 |
     +----------------+


Sergiy

On Mon, Jun 10, 2013 at 9:33 PM, PKCHEN UMD <pkchen@umd.edu> wrote:
> Hello Statalist,
> I have a time-series cross sections dyad-year dataset. I run the
> regression and create the prediction variable for each observation. I
> want to take the prediction of the first year of each dyad and times
> 1.3. There is one number for the beginning year of every dyad. Then I
> want to compare the rest of years of prediction with the beginning
> year. My goal is to create a dummy variable that is 1 if any yearly
> prediction for that dayd is more than 1.3*the beginning year
> prediction.
>
> I manage to create a variable that contains the 1.3*the first year
> prediction using by dyad: gen. But I can only tell stata to fill in
> the value of the beginning. The rest of yearly observations are coded
> as missing. Is there a command that can autofill the missing value
> with the first year prediction I create? Or is there a more succinct
> way to create the dummy variable I want?
>
> Thank you very much!
>
> --
> Ping-Kuei Chen
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index