Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Generating new variable from selected observations

From   "Austin Nichols" <>
Subject   Re: st: Generating new variable from selected observations
Date   Sat, 18 Mar 2006 10:46:19 -0500

1. "Didn't work" is not a useful thing to state in any request for
help. 2. Read -help for-, which indicates 3. Avoid -for- and read
-help foreach- for the reasons discussed on the list previously.  This
all comes before the post to Statalist.

In this case, however, I think you are better off not using a loop,
but -collapse-
. replace id=14 if id==27
. collapse var*, by(id)
if you want means for each var by id.  But you don't have one
observation with two sets of responses; you have two observations on
the same id--if you take the mean you are claiming that neither
observation is correct, but the mean of both is.  I hope there aren't
any categorical responses--instead of 1 for Yes and 0 for No, you will
wind up with 0.5 for Who knows.  Maybe you should leave both responses
in and cluster on id, depending on what your data look like and what
you are doing with them.

On 3/17/06, Julian Jiro Wimbush <> wrote:
> Hello,
> I'm trying to adjudicate one observation that has two sets of responses by taking the mean for all
> my variablers in the two sets of responses and using those means as the data.
> More specifically: each observation is a medical center, and one medical center sent in two
> completed surveys (two different people in the org somehow responded), and I simply want what is
> currently coded incorrectly as two medical center observations to be one medical center
> observation, basically by taking the means of two sets of responses for all my variables.  So I
> started writing some code like this:
> for variable1-variable200: ltype(numeric): replace @=(@[14]+@[27])/2, if id==14 or id==27
> and then simply dropping observation 27, but it didn't work. (I was trying to specify observation
> 14 and 27 in the replace part, but I think I've done something completely different.)
> I have a feeling I may well be completely on the wrong track, but any help would be appreciated!
>   Thanks in advance.
> Julian
> *
> *   For searches and help try:
> *
> *
> *

*   For searches and help try:

© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index