如何在Stata中同时估算两个变量?

时间:2016-04-18 22:42:53

标签: stata imputation

我试图在Stata中同时输入两个变量:比如y和x。然后我想对它们进行线性回归。

我使用的代码是:

mi set mlong
mi register imputed y x

mi impute regress y a b c, add(10)
mi impute regress x a b c, add(10)
mi estimate: regress y x

我遇到错误:" 估算样本在m = 1和m = 11 "之间变化。有人可以帮我吗?谢谢!

1 个答案:

答案 0 :(得分:0)

我更喜欢使用链式方程式。下面的代码应该可以工作(请注意,可以跳过第1部分,因为我只使用它来生成合适的模拟数据集):

* Part 1

clear all
set seed 0945 
set obs 50
gen y0 = _n 
gen y = runiform()
sort y
gen x0 = _n
gen x = runiform()
sort x
replace y = . in 1
replace y = . in 5
replace y = . in 10
replace y = . in 15
replace y = . in 20
replace y = . in 25
replace y = . in 30
replace y = . in 35
replace y = . in 40
replace y = . in 45
replace y = . in 50
sort y
replace x = . in 1
replace x = . in 5
replace x = . in 10
replace x = . in 15
replace x = . in 20
replace x = . in 25
replace x = . in 30
replace x = . in 35
replace x = . in 40
replace x = . in 45
replace x = . in 50
gen a = _n 
sort x
gen b = _n 
gen c = _n 

* Part 2

mi set mlong
mi register imputed y x

mi impute chained (regress) y x = a b c, add(10)
mi estimate, dots: regress y x