Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: calcuating unadjusted and adjusted means


From   Ronan Conroy <rconroy@rcsi.ie>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: calcuating unadjusted and adjusted means
Date   Mon, 16 May 2011 10:59:55 +0100

On 2011 Beal 15, at 15:01, Fitzmaurice, Ann E. wrote:

> 
> I run the following where the variable bir_grp has four categories  was entered in the regression as i.bir_grp2 (sample_mod5 has previously been calculated)
> Regress ............
> predict xb
> rename xb pred_m5
> mean pred_m5 if sample_mod5 ==1 , over (bir_grp2)
> 
> adjust if sample_mod5==1, by (bir_grp2)
> 
> after this command I get an error message " variable miscbirth not found"

Reproducible. If you run a command after -regress- (in this case, -mean-) you will lose some or all of the stored results needed to run -adjust-.

Incidentally, you can name a predicted variable in the -predict- command, as below. 

The solution is to do all the -predict-ing and -adjust-ing first, then run other commands. 

. regress mpg weight price

      Source |       SS       df       MS              Number of obs =      74
-------------+------------------------------           F(  2,    71) =   66.85
       Model |  1595.93249     2  797.966246           Prob > F      =  0.0000
    Residual |  847.526967    71  11.9369995           R-squared     =  0.6531
-------------+------------------------------           Adj R-squared =  0.6434
       Total |  2443.45946    73  33.4720474           Root MSE      =   3.455

------------------------------------------------------------------------------
         mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      weight |  -.0058175   .0006175    -9.42   0.000    -.0070489   -.0045862
       price |  -.0000935   .0001627    -0.57   0.567     -.000418    .0002309
       _cons |   39.43966   1.621563    24.32   0.000     36.20635    42.67296
------------------------------------------------------------------------------

. predict p_mpg
(option xb assumed; fitted values)

. mean p_mpg, over( foreign)

Mean estimation                     Number of obs    =      74

     Domestic: foreign = Domestic
      Foreign: foreign = Foreign

--------------------------------------------------------------
        Over |       Mean   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
p_mpg        |
    Domestic |   19.57435   .5887395        18.401    20.74771
     Foreign |   25.36971   .5838502       24.2061    26.53332
--------------------------------------------------------------


. adjust, by( foreign)
variable Domestic not found
r(111);



Ronán Conroy
rconroy@rcsi.ie
Associate Professor
Division of Population Health Sciences
Royal College of Surgeons in Ireland
Beaux Lane House
Dublin 2


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index