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: data management question


From   Caroline Wilson <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: data management question
Date   Wed, 18 Sep 2013 22:54:32 +0000

Apologies for the confusion - the variable "value" should have been called "Md_T".
Anyway, your solution worked perfectly - very many thanks!!!!

Caroline

----------------------------------------
> Date: Wed, 18 Sep 2013 18:33:19 -0400
> From: [email protected]
> To: [email protected]
> Subject: Re: st: data management question
>
>
>
> On Wed, 18 Sep 2013, Caroline Wilson wrote:
>
>> Hello,
>>
>>
>>
>> I’m wondering if someone can help with a data management
>> question.
>>
>>
>>
>> I’m trying to create a variable called “mean”, which, for a given
>> pat_ID, would be calculated by taking the mean of every other value of
>> “Md_T” in the same phy_ID EXCEPT for the current row.
>>
>
> I am a little unclear on what you are asking - Md_T isn't in the sample
> data you show, but you want the mean of it? So I won't use your variable
> names. Nevertheless, I think that the -egen- -total- function and a
> generate statement will get you what you want:
>
> by ID: egen sum=total(var)
> generate sumex= sum-var
> by ID: generate meanex = sumex/(_N-1)
>
> The total by ID gives the sum of var for each level of ID. Then we
> subtract the current level of var and divide by the number of observations
> in the ID group. (_N is the number of observations in the by group).
>
> Daniel Feenberg 		 	   		  
*
*   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