Tuesday, October 25, 2011

Can 'margins' be used after 'mi estimate'?

Can 'margins' be used after 'mi estimate'?

The -margins- command may not be used in the usual way after -mi estimate-. You'll need to write a short "wrapper command" that can be run with the -mi estimate- prefix. My colleagues outlined the method on Statalist: Average marginal effects for a multiply imputed complex survey. You'll want to change the 11 in the -version 11- statement to 12. One of our FAQs will also be helpful: How can I combine results other than coefficients in e(b) with multiply imputed data? - by A Statistician, Stata


Here is my modified program based on codes of UCLA Stata Portal

use http://www.ats.ucla.edu/stat/data/hsbmar, clear
/* set MI dataset */
mi set mlong
mi register imputed female math read science socst
mi svyset [pw=write], strata(ses)
mi impute chain (logit) female (regress) math read science socst ///
       =ses write awards, add(10) rseed(123456)
/* program */
capture program drop mimargins
program mimargins, eclass properties(mi)
  version 12
  svy: logit honors i.female##i.prog read math science socst
  margins female#prog, post
end
/* run the program */ 
mi estimate, cmdok: mimargins 1
matlist r(table)'*100, tw(20) format(%8.2f)
mi estimate (_b[1.female#2.prog]/_b[1.female#1bn.prog]): mimargins 1

Notes: The 'cmdok' option forces 'mi estimate' to estimate the current Stata unsupported model. The 'cmdok' is not necessary because of already including the 'properties(mi)' in the program.

mi estimate: svy: logit honors i.female##i.prog read math science socst
mi test 1.female#2.prog 1.female#3.prog

mi estimate (diff:1.female#2.prog-1.female#3.prog), saving(miest, replace): svy: logit honors i.female##i.prog read math science socst
mi testtransform diff

mi estimate (rdiff:1.female#2.prog/1.female#3.prog - 1) using miest
mi testtr rdiff


Useful Resources:


1 comment:

sh said...

Nice job!
Could you mind telling me how to modify this for linear regression?
Thanks!