楼主: 皇宁存昂
1328 2

[作图问题求助] An error occurs when doing marginsplot for categorical by continous interaction [推广有奖]

  • 0关注
  • 3粉丝

已卖:191份资源

博士生

51%

还不是VIP/贵宾

-

威望
0
论坛币
2261 个
通用积分
24.1817
学术水平
0 点
热心指数
1 点
信用等级
1 点
经验
11337 点
帖子
358
精华
0
在线时间
208 小时
注册时间
2011-3-16
最后登录
2025-10-18

楼主
皇宁存昂 在职认证  发表于 2016-8-14 18:13:57 |AI写论文
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

关键词:Categorical interaction continous interact Margins imputation marginsplot education economic multiple

沙发
黃河泉 在职认证  发表于 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
那边如有回复读者也可参考。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-26 18:44