约束坡度

时间:2014-04-03 22:07:51

标签: regression stata

我是Stata的初学者。我正在尝试运行以下回归:

regress logy logI logh logL

但我想将logh的斜率约束为1。有人可以告诉我这个命令吗?

1 个答案:

答案 0 :(得分:5)

在Stata中至少有三种方法可以做到这一点。

1)使用约束线性回归:

. sysuse auto
(1978 Automobile Data)

. constraint 1 mpg = 1

. cnsreg price mpg weight, constraints(1)

Constrained linear regression                     Number of obs   =         74
                                                  Root MSE        =  2502.5449

 ( 1)  mpg = 1
------------------------------------------------------------------------------
       price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         mpg |          1  (constrained)
      weight |   2.050071   .3768697     5.44   0.000     1.298795    2.801347
       _cons |  -46.14764   1174.541    -0.04   0.969    -2387.551    2295.256
------------------------------------------------------------------------------

2)变量转换(由上面评论中的whuber建议):

. gen price2 = price - mpg

. reg price2 weight 

      Source |       SS       df       MS              Number of obs =      74
-------------+------------------------------           F(  1,    72) =   29.59
       Model |   185318670     1   185318670           Prob > F      =  0.0000
    Residual |   450916627    72  6262730.93           R-squared     =  0.2913
-------------+------------------------------           Adj R-squared =  0.2814
       Total |   636235297    73  8715552.01           Root MSE      =  2502.5

------------------------------------------------------------------------------
      price2 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      weight |   2.050071   .3768697     5.44   0.000     1.298795    2.801347
       _cons |  -46.14764   1174.541    -0.04   0.969    -2387.551    2295.256
------------------------------------------------------------------------------

3)使用具有偏移量的GLM模型:

. glm price weight , family(gaussian) link(identity) offset(mpg)

Iteration 0:   log likelihood = -683.04238  
Iteration 1:   log likelihood = -683.04238  

Generalized linear models                          No. of obs      =        74
Optimization     : ML                              Residual df     =        72
                                                   Scale parameter =   6262731
Deviance         =  450916626.9                    (1/df) Deviance =   6262731
Pearson          =  450916626.9                    (1/df) Pearson  =   6262731

Variance function: V(u) = 1                        [Gaussian]
Link function    : g(u) = u                        [Identity]

                                                   AIC             =  18.51466
Log likelihood   = -683.0423847                    BIC             =  4.51e+08

------------------------------------------------------------------------------
             |                 OIM
       price |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      weight |   2.050071   .3768697     5.44   0.000      1.31142    2.788722
       _cons |  -46.14764   1174.541    -0.04   0.969    -2348.205    2255.909
         mpg |          1  (offset)
------------------------------------------------------------------------------

如果您正确更改链接和系列选项,glm路径还可以为您处理结果的日志转换。