我有以下模型:
ivreg ldemand social_housing transport year (lprice = utilities)
但是,我想将year
作为虚拟变量。
我如何在Stata中做到这一点?
使用i.year
不能用于ivreg
命令。
交叉发布于Statalist。
答案 0 :(得分:1)
命令ivreg
不允许使用因子变量:
. webuse hsng2, clear
. ivreg rent pcturban i.region (hsngval = faminc)
factor variables not allowed
r(101);
但是,您仍然可以使用xi
前缀动态创建虚拟对象:
. xi: ivreg rent pcturban i.region (hsngval = faminc)
i.region _Iregion_1-4 (naturally coded; _Iregion_1 omitted)
Instrumental variables (2SLS) regression
Source | SS df MS Number of obs = 50
-------------+---------------------------------- F(5, 44) = 9.10
Model | 12735.4667 5 2547.09334 Prob > F = 0.0000
Residual | 48507.6533 44 1102.44667 R-squared = 0.2079
-------------+---------------------------------- Adj R-squared = 0.1179
Total | 61243.12 49 1249.85959 Root MSE = 33.203
------------------------------------------------------------------------------
rent | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
hsngval | .0038683 .0008958 4.32 0.000 .0020629 .0056737
pcturban | -.4980121 .5179779 -0.96 0.342 -1.541928 .5459039
_Iregion_2 | 1.528672 15.14086 0.10 0.920 -28.98572 32.04306
_Iregion_3 | 7.74279 15.10906 0.51 0.611 -22.70752 38.1931
_Iregion_4 | -40.61235 19.60999 -2.07 0.044 -80.13369 -1.091002
_cons | 88.26681 31.69154 2.79 0.008 24.39671 152.1369
------------------------------------------------------------------------------
Instrumented: hsngval
Instruments: pcturban _Iregion_2 _Iregion_3 _Iregion_4 faminc
------------------------------------------------------------------------------
重要的是要注意,根据命令的帮助文件:
过期命令
ivreg 是Stata 10以来的过期命令。 ivreg 已由 ivregress 命令替换。
因此,最好改用ivregress
:
. ivregress 2sls rent pcturban i.region (hsngval = faminc), small
Instrumental variables (2SLS) regression
Source | SS df MS Number of obs = 50
-------------+------------------------------ F( 5, 44) = 9.10
Model | 12735.4667 5 2547.09334 Prob > F = 0.0000
Residual | 48507.6533 44 1102.44667 R-squared = 0.2079
-------------+------------------------------ Adj R-squared = 0.1179
Total | 61243.12 49 1249.85959 Root MSE = 33.203
------------------------------------------------------------------------------
rent | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
hsngval | .0038683 .0008958 4.32 0.000 .0020629 .0056737
pcturban | -.4980121 .5179779 -0.96 0.342 -1.541928 .5459039
|
region |
N Cntrl | 1.528672 15.14086 0.10 0.920 -28.98572 32.04306
South | 7.74279 15.10906 0.51 0.611 -22.70752 38.1931
West | -40.61235 19.60999 -2.07 0.044 -80.13369 -1.091002
|
_cons | 88.26681 31.69154 2.79 0.008 24.39671 152.1369
------------------------------------------------------------------------------
Instrumented: hsngval
Instruments: pcturban 2.region 3.region 4.region faminc
在Stata的命令提示符下键入help ivregress
,以获取更多详细信息。