全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
1303 2
2016-08-14
悬赏 10 个论坛币 未解决
Hi all,

I am trying to use marginsplots to graph a categorical by continous variable interaction between migrant status(pms4, 4 categories) and years of education (eduy) for a regression model predicting social economic status (ses) using multiple imputed data. I used the code from the ATS UCLA website as a template (http://www.ats.ucla.edu/stat/stata/f...arginsplot.htm). However, I'm getting an error when I run it. Here is the code:

program emargins2, eclass properties(mi)
version 13
args outcome
reg isei i.pms4##c.eduy male age fisei14 eduy
margins pms4, at(eduy=(0(1)21)) atmeans asbalanced ///
post predict(outcome(`outcome'))
end

program myret, rclass
return add
return matrix b = b
return matrix V= V
end

mi estimate: reg isei i.pms4##c.eduy male age fisei14
mi estimate, cmdok: emargins 1 // emargins is defined above

---------------------
And I get an error when running the "mi estimate, cmdok: emargins 1 " below is the error.

option outcome() not allowed
an error occurred when mi estimate executed emargins on m=1
r(198);

-------------------
The same error message occurs when I use the alternative code ( to mimic the template):

forvalues i=1/1 {

mi estimate, cmdok: emargins `i' // emargins is defined above
mat b= e(b_mi) // save mi point estimates
mat V = e(V_mi) // save mi vce

* run ologit and margins on the _mi_m==0 data
quietly reg isei i.pms4##c.eduy male age fisei14 if _mi_m == 0
quietly margins pms4, at(eduy=(0(1)21)) atmeans ///
asbalanced predict(outcome(`i'))

* myret puts b and V matrix in a place marginsplot can find
myret

*Technically we ran the program myret between margins and marginsplot.
*E(cmd) is the eclass scalar that tells Stata what the previous command was.
*So we have to set that to "margins" for marginsplot to work correctly
*(becaues marginsplot expects margins as the last estimation command).
mata: st_global("e(cmd)", "margins") // set previous cmd to margins

marginsplot, title("predicted SES") name(ses1,replace)
}


Thanks for reading! Any help would be appreciated.




BTW, I've already set the data to be the mi-form by the following code:

set seed 5576
mi set mlong
mi register imputed fisei14
mi impute regress fisei14 = isei eduy male age,add(20) force by(pms4)




Best,
Tianzhu
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2016-8-15 16:24:22
You asked too many questions in a post. (i) Is it necessary for you to use the command "mi" (missing values)? I'd like to suggest not to use "mi" command so as to make things simple/tractable. (2) Is the dependent variable "isei" a standard one (not discrete, censored, truncated, and so on)?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-8-15 22:17:08
楼主的另一贴在http://www.statalist.org/forums/forum/general-stata-discussion/general/1352910-an-error-occurs-when-doing-marginsplot-for-categorical-by-continous-interaction-with-multiply-imputed-data
那边如有回复读者也可参考。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群