Tuesday, November 08, 2011

Tips - Stata: how to do 'lincom' after a three-way 'margins'?

Tips - Stata: how to do 'lincom' after a three-way 'margins'?
The easiest way to determine how to refer to the margins is to type
   .margins, coeflegend
after the -margins- command. This will list the estimated margins as well as the _b[] notation that can be used to refer to them. Here is an example:
   .webuse nhanes2, clear
   .svy, subpop(female): logit highbp i.race##i.diabetes##c.age weight
   .margins race, over(diabetes) at(age = (30(5)50)) subpop(female) ///

            vce(svy) post
  .margins, coeflegend

This tells us that if we want to compute the difference in the margins for age=30, diabetes=0, race=1 and age=35, diabetes=0, race=1, we could type
   .lincom _b[1bn._at#0bn.diabetes#1bn.race] - ///
           _b[2._at#0bn.diabetes#1bn.race]
-- by a senior statistician of Stata

No comments: