Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st:egen mean excludign any variable with missing values


From   Glenn Goldsmith <[email protected]>
To   [email protected]
Subject   RE: st:egen mean excludign any variable with missing values
Date   Mon, 8 Jun 2009 10:18:33 +0100

<>

An alternative solution, which avoids having to run a regression
first, is to use -mark- and -markout-:

  mark touse
  markout touse Y x-x8
  foreach v of varlist Y x1-x8 {
    by id: egen mean_`v'=mean(`v') if touse
  }

HTH,

Glenn

Roy Wada <[email protected]> wrote:

> I want to demean variables Y, x1-x8 and then run an OLS regression of
> these variables for a panel data set for respondents. I think I need
> to be careful with the missing values in these variables. I'm not sure
> to exclude any respondent who has missing values for any of the
> variable in Y, x1-x8 when calculating the group mean for each
> respondent.
>
> Mandy

You can take advantage of -reg- to perform casewise deletion.

qui reg y x-x8
foreach v of varlist Y x1-x8 {
   by id: egen mean_`v'=mean(`v') if e(sample)==1
}

Roy
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index