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   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Replace value for some observation with average values of some other observations?
Date   Wed, 18 Jan 2012 13:42:05 +0000

I naturally agree with Stas and in fact deleted a flippant remark about R before posting. 

The FAQ already carries advice on using real names. 

http://www.stata.com/support/faqs/res/statalist.html#tojoin

"It is long-standing practice on Statalist that most members, especially the most active members who supply a large fraction of the answers, post using their real names. This is one of the ways in which we show respect to others. So we discourage you from posting from behind fake names or identifiers. Such handles are particularly objectionable if they include the word "Stata" in some way. Please note that many members are less inclined to answer anonymous emails, sometimes to the point of ignoring them on principle. These choices are personal, but your chances of eliciting a good reply are greatly diminished if you write and conceal your identity. Conversely, if you decide just to watch and read on the list, your email identity remains entirely up to you."

Nick 
n.j.cox@durham.ac.uk 


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Stas Kolenikov
Sent: 18 January 2012 13:30
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Replace value for some observation with average values of some other observations?

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.


*
*   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