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: Replace value for some observation with average values of some other observations?


From   Scott Merryman <[email protected]>
To   [email protected]
Subject   Re: st: Replace value for some observation with average values of some other observations?
Date   Wed, 18 Jan 2012 06:27:02 -0600

sum outcome  if id == 2 | id ==3replace outcome = r(mean) if id == 1

Scott


On Wed, Jan 18, 2012 at 6:16 AM, Stata Chris <[email protected]> wrote:
> Dear list members,
>
> Suppose I have a dataset with variables id and outcome.
> Now for the observation with id=1 I want to replace the value of the
> outcome by the average outcome values of the observations with id=2
> and id=3.
>
> I thought of
>
> replace outcome=mean(outcome[id==2],outcome[id==3]), but this does not
> quite work.
>
> Would anyone know how to do this correctly?
>
> Thank you so much,
> C
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index