【问题标题】:Regression with all variables without explicitly declaring them回归所有变量而不显式声明它们
【发布时间】:2019-12-03 22:28:34
【问题描述】:

我有一个数据集,我想在 Stata 中运行回归。我想将其中一个虚拟变量作为基础,所以我在regress 命令中使用了ib1.month1

是否可以在我的回归中包含数据集中的所有其他变量而无需再次明确写出每个变量?

【问题讨论】:

    标签: function stata


    【解决方案1】:

    您可以使用ds 命令:

    sysuse auto, clear
    drop make 
    
    ds price foreign, not 
    
    regress price ib1.foreign `r(varlist)' 
    
          Source |       SS           df       MS      Number of obs   =        69
    -------------+----------------------------------   F(10, 58)       =      8.66
           Model |   345416162        10  34541616.2   Prob > F        =    0.0000
        Residual |   231380797        58  3989324.09   R-squared       =    0.5989
    -------------+----------------------------------   Adj R-squared   =    0.5297
           Total |   576796959        68  8482308.22   Root MSE        =    1997.3
    
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
         foreign |
       Domestic  |  -3334.848   957.2253    -3.48   0.001    -5250.943   -1418.754
             mpg |  -21.80518    77.3599    -0.28   0.779    -176.6578    133.0475
           rep78 |   184.7935   331.7921     0.56   0.580    -479.3606    848.9476
        headroom |  -635.4921   383.0243    -1.66   0.102    -1402.198    131.2142
           trunk |   71.49929   95.05012     0.75   0.455    -118.7642    261.7628
          weight |   4.521161   1.411926     3.20   0.002     1.694884    7.347438
          length |  -76.49101   40.40303    -1.89   0.063    -157.3665     4.38444
            turn |  -114.2777   123.5374    -0.93   0.359    -361.5646    133.0092
    displacement |   11.54012   8.378315     1.38   0.174    -5.230896    28.31115
      gear_ratio |  -318.6479    1124.34    -0.28   0.778    -2569.259    1931.964
           _cons |   13124.34     6726.3     1.95   0.056    -339.8103     26588.5
    ------------------------------------------------------------------------------
    

    【讨论】:

    • 请注意,一般情况下,所有变量都不能包含任何字符串变量。在这里的例子中,make 是唯一的字符串变量,所以@Pearly Spencer 只是dropped 它。但请注意,ds, has(type numeric) 是一个忽略所有字符串变量的过滤器。
    猜你喜欢
    • 1970-01-01
    • 2013-03-10
    • 1970-01-01
    • 1970-01-01
    • 2017-04-22
    • 1970-01-01
    • 2022-11-25
    • 1970-01-01
    • 2019-10-27
    相关资源
    最近更新 更多