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]

Re: st: How to fill in the missing data


From   Michael Stewart <[email protected]>
To   statalist <[email protected]>
Subject   Re: st: How to fill in the missing data
Date   Mon, 10 Jun 2013 01:09:56 -0400

hi
Did you check carryforward user written module, looks like it will help you
ssc install  carryforward
Mike

On Mon, Jun 10, 2013 at 12:45 AM, Ching Wong
<[email protected]> wrote:
> 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/



-- 
Thank you ,
Yours Sincerely,
Mike.
*
*   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