如何解决如何从Stata中的分类变量自动创建虚拟变量?
如何generate
自动从因子/类别变量创建假人/指标?
解决方案来自尼克:tabulate group,generate(g)
* Load data
clear
use http://www.stata-press.com/data/r13/nlswork
* Set panel structure
xtset idcode year
* Delete other variables
keep idcode year ln_wage union tenure age race occ_code
* Complete Cases
drop if union ==.
drop if tenure ==.
drop if occ_code ==.
* Generate dummies automatically
tabulate race,generate(r)
tabulate occ_code,generate(occ)
generate tr1 = tenure*r1
generate tr2 = tenure*r2
generate tr3 = tenure*r3
* Interaction with factor notation
reg ln_wage c.tenure##i.race i.occ_code age union
*margins,dydx(tenure) post
estimates store reg_factor
* Interaction without factor notation
reg ln_wage tenure r1 r2 r3 tr1 tr2 tr3 age union ///
occ1 occ2 occ3 occ4 occ5 occ6 occ7 occ8 occ9 occ10 occ11 occ12 occ13
*margins,dydx(tenure) post
estimates store reg_dummies
estimates table reg_factor reg_dummies
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。