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   "Fitzmaurice, Ann E." <a.e.fitzmaurice@abdn.ac.uk>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: calcuating unadjusted and adjusted means
Date   Mon, 16 May 2011 16:16:51 +0100

Thankyou for this

Here is the commands that I run

What I get is the unadjusted means in stata  (have checked this out by running the regression in another stats package) and then getting the unadjusted and adjusted means for the same sample

I am sure that I need to make a small tweak to the code below, but don't know what the tweak is

Thanks

Ann

regress babywt2 ib(last).bir_grp2  ib(last).ht_grp1a  ib(last).mstat2b ib(3).hsc2a_mr ///
 ib(last).delt2a_m ib(last).bpre2c   ib(last).bsex2a ib(last).pet2a_mr ///
  ib(last).aph2a_mr  ib(last).int5_mr ib(last).yrdel2a_mr  if ( sample_mod6==1)

 predict xb
 mean xb if sample_mod6 ==1 , over (bir_grp2)
rename xb pred_m6
 mean babywt2  if sample_mod6 ==1, over (bir_grp2)

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Ronan Conroy
Sent: 16 May 2011 11:00
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: calcuating unadjusted and adjusted means

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/


The University of Aberdeen is a charity registered in Scotland, No SC013683.

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