Bookmark and Share

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]

st: How to fill in the missing data


From   Ching Wong <[email protected]>
To   [email protected]
Subject   st: How to fill in the missing data
Date   Mon, 10 Jun 2013 14:15:42 +0930

Hi,

I have a dataset as following:

id age weight
1   21   50.2
1   22
1   23   52.9
1   24   51.0
1   25
2   22
2   23
2   25   60.2
3   21

And I would like to create a new variable "weight2" and fill in the
missing data based on the previous value

My expected output value should be as follows:

id age weight weight2
1   21   50.2     50.2
1   22       .       50.2
1   23   52.9     52.9
1   24   51.0     51.0
1   25      .        51.0
2   22      .            .
2   23      .            .
2   25   60.2     60.2
3   21      .            .

I have tried the command below but that cannot produce what I expected.

- bysort id (age): gen weight_hat = weight[_n-1]

It is very obvious that command is missing something. So what will be
the correct command in this case?

Cheers,

Wong
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index