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]

From |
Stas Kolenikov <skolenik@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Replace value for some observation with average values of some other observations? |

Date |
Wed, 18 Jan 2012 08:30:16 -0500 |

On Wed, Jan 18, 2012 at 8:21 AM, Nick Cox <n.j.cox@durham.ac.uk> wrote: > Scott's answer is two command lines and answers the question perfectly. > > I've edited it below because as received the two lines were run together. > > The solution from "Stata Chris" that does "not quite work" doesn't work for the following reasons: > > 1. A invocation to -mean()- on the right-hand side of a -replace- statement could only work if there a Stata function (strict sense) -mean()-, but no such function exists. > > 2. There is an -egen- function -mean()- but it can't be used in -replace- and it doesn't have a syntax anything like Chris' example. > > 3. -outcome[id==2]-, say, with reference to a variable -outcome- would in context evaluate to -outcome[0]- which is missing or -outcome[1]- which would be the first value of -outcome-, depending on the evaluation of -id == 2-. It never means subset of -outcome- for which -id- is 2. Chris is referring to R syntax: the line outcome[id==1] <- mean( c(outcome[id==2],outcome[id==3]) ) would work just fine in R, and produce the desired result. Mixing the two languages is never a good idea; nobody on R lists can ever answer questions like "How do I merge m:1 id using blah, keep(match) keepusing(this and that)"? I would add that "Stata Chris" isn't a very good name for this list. It might be convenient for you, but in my email client (Gmail), this discussion is shown as "Stata, Scott, Nick". Stata Corp won't sue you for this, but it does create confusion. -- Stas Kolenikov, also found at http://stas.kolenikov.name Small print: I use this email account for mailing lists only. * * 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/

**Follow-Ups**:**RE: st: Replace value for some observation with average values of some other observations?***From:*Nick Cox <n.j.cox@durham.ac.uk>

**References**:**st: Replace value for some observation with average values of some other observations?***From:*Stata Chris <statachris@gmail.com>

**Re: st: Replace value for some observation with average values of some other observations?***From:*Scott Merryman <scott.merryman@gmail.com>

**RE: st: Replace value for some observation with average values of some other observations?***From:*Nick Cox <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: RE: a question on averaging in Stata** - Next by Date:
**st: Tabulating multiple Likert-variable frequencies** - Previous by thread:
**RE: st: Replace value for some observation with average values of some other observations?** - Next by thread:
**RE: st: Replace value for some observation with average values of some other observations?** - Index(es):