Statalist The Stata Listserver


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

Re: st: Using the constant term from ANOVA in lincom


From   [email protected]
To   [email protected]
Subject   Re: st: Using the constant term from ANOVA in lincom
Date   Thu, 20 Jul 2006 16:02:35 -0500

Richard Steiner <[email protected]> asks:

> I'm having trouble using the constant term in lincom following an ANOVA.
> Here's what I've done:
> 
> #delimit ;
> anova y 
>       subj|group group tmcond method
>       group*tmcond group*method tmcond*method
>       group*tmcond*method;
> 
> ...ANOVA Output produced...
> 
> lincom _cons+_coef[group[1]]+_coef[tmcond[1]]+_coef[method[1]]
>        +_coef[group[1]*tmcond[1]]+_coef[group[1]*method[1]]
>        +_coef[tmcond[1]*method[1]]+_coef[group[1]*tmcond[1]*method[1]];
> invalid syntax
> r(198);
> 
> It seemed that lincom could not reference the constant term _cons, so I
> tried another tack by explicitly fitting the constant:

In the -lincom- call just change _cons to _coef[_cons] in the
above and it will work.


In your next attempt:

> gen const = 1
> 
> #delimit ;
> anova y 
>       const subj|group group tmcond method
>       group*tmcond group*method tmcond*method
>       group*tmcond*method, noconstant;
> 
> ...ANOVA Output produced...
> 
> lincom _coef[const]+_coef[group[1]]+_coef[tmcond[1]]+_coef[method[1]]
>        +_coef[group[1]*tmcond[1]]+_coef[group[1]*method[1]]
>        +_coef[tmcond[1]*method[1]]+_coef[group[1]*tmcond[1]*method[1]];
> _b[const] not found
> r(111);
> 
> In either case I can't use the constant term in lincomp. Any suggestions are
> welcome. I'm looking for the model estimate of the mean and its se for the
> group==1, method==1, tmcond==1 cell of the design.

you just need to change _coef[const] to _coef[const[1]] and it
will work.  But I assume you will instead go with the first
method so you don't have to create your own constant.


To double check myself I used the following commands:

  // I first create some data
  clear
  set obs 3
  gen group = _n
  expand 4
  sort group
  by group: gen subj = _n
  expand 2
  sort group subj
  by group subj: gen tmcond = _n
  expand 2
  sort group subj tmcond
  by group subj tmcond: gen method = _n
  sort group subj tmcond method
  set seed 38292
  gen y = group*2 + tmcond - method*3 + invnormal(uniform())

  // Now I do what you were trying, with my fixes applied
  #delimit ;
  anova y 
        subj|group group tmcond method
        group*tmcond group*method tmcond*method
        group*tmcond*method;

  lincom _coef[_cons]+_coef[group[1]]+_coef[tmcond[1]]+_coef[method[1]]
         +_coef[group[1]*tmcond[1]]+_coef[group[1]*method[1]]
         +_coef[tmcond[1]*method[1]]+_coef[group[1]*tmcond[1]*method[1]];

  gen const = 1 ;

  anova y 
        const subj|group group tmcond method
        group*tmcond group*method tmcond*method
        group*tmcond*method, noconstant;

  lincom _coef[const[1]]+_coef[group[1]]+_coef[tmcond[1]]+_coef[method[1]]
         +_coef[group[1]*tmcond[1]]+_coef[group[1]*method[1]]
         +_coef[tmcond[1]*method[1]]+_coef[group[1]*tmcond[1]*method[1]];
  #delimit cr

Let me know if this does not work for you.


Ken Higbee    [email protected]
StataCorp     1-800-STATAPC

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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