【问题标题】:Interaction Variables when Factor Variables are not allowed (Stata)不允许使用因子变量时的交互变量(Stata)
【发布时间】:2015-11-04 09:06:55
【问题描述】:

我正在 Stata 中运行回归,我想使用 cluster2 (http://www.kellogg.northwestern.edu/faculty/petersen/htm/papers/se/se_programming.htm)。

我遇到以下问题。 Stata 报告factor variables and time-series operators not allowed。我正在使用大量控件向量,广泛应用 Stata 提供的交互方法。

例如:state##c.wind_speed##L.c.relative_humiditycluster2 和其他 Stata 软件包不允许包含这样的表达式作为自变量。有没有一种有效的方法可以自己创建如此长的交互变量向量?

【问题讨论】:

    标签: stata


    【解决方案1】:

    我相信可以通过 Baum-Shaffer-Stillman 欺骗 ivreg2 从而运行具有双向集群和交互的 OLS:

    . webuse nlswork
    (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
    
    . ivreg2 ln_w grade c.age##c.ttl_exp tenure, cluster(idcode year)
    
    OLS estimation
    --------------
    
    Estimates efficient for homoskedasticity only
    Statistics robust to heteroskedasticity and clustering on idcode and year
    
    Number of clusters (idcode) =     4697                Number of obs =    28099
    Number of clusters (year) =         15                F(  5,    14) =   674.29
                                                          Prob > F      =   0.0000
    Total (centered) SS     =  6414.823933                Centered R2   =   0.3206
    Total (uncentered) SS   =  85448.21266                Uncentered R2 =   0.9490
    Residual SS             =  4357.997339                Root MSE      =    .3938
    
    ---------------------------------------------------------------------------------
                    |               Robust
            ln_wage |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    ----------------+----------------------------------------------------------------
              grade |   .0734785    .002644    27.79   0.000     .0682964    .0786606
                age |  -.0005405    .002259    -0.24   0.811    -.0049681    .0038871
            ttl_exp |   .0656393   .0068499     9.58   0.000     .0522138    .0790648
                    |
    c.age#c.ttl_exp |  -.0010539   .0002217    -4.75   0.000    -.0014885   -.0006194
                    |
             tenure |   .0197137   .0029555     6.67   0.000      .013921    .0255064
              _cons |   .5165052   .0529343     9.76   0.000     .4127559    .6202544
    ---------------------------------------------------------------------------------
    Included instruments: grade age ttl_exp c.age#c.ttl_exp tenure
    ------------------------------------------------------------------------------
    

    只是为了确保将其与 OLS 系数进行比较:

    . reg ln_w grade c.age##c.ttl_exp tenure
    
          Source |       SS           df       MS      Number of obs   =    28,099
    -------------+----------------------------------   F(5, 28093)     =   2651.79
           Model |  2056.82659         5  411.365319   Prob > F        =    0.0000
        Residual |  4357.99734    28,093  .155127517   R-squared       =    0.3206
    -------------+----------------------------------   Adj R-squared   =    0.3205
           Total |  6414.82393    28,098  .228301798   Root MSE        =    .39386
    
    ---------------------------------------------------------------------------------
            ln_wage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    ----------------+----------------------------------------------------------------
              grade |   .0734785   .0010414    70.55   0.000     .0714373    .0755198
                age |  -.0005405    .000663    -0.82   0.415    -.0018401    .0007591
            ttl_exp |   .0656393   .0030809    21.31   0.000     .0596007    .0716779
                    |
    c.age#c.ttl_exp |  -.0010539   .0000856   -12.32   0.000    -.0012216   -.0008862
                    |
             tenure |   .0197137   .0008568    23.01   0.000     .0180344     .021393
              _cons |   .5165052   .0206744    24.98   0.000     .4759823     .557028
    ---------------------------------------------------------------------------------
    

    【讨论】:

      【解决方案2】:

      您没有提供可验证的示例。请参阅https://stackoverflow.com/help/mcve 获取关键建议。

      然而,乍一看,问题在于 cluster2 是一个在 2006/2007 年编写的旧程序,其 syntax 语句不允许因子变量。

      您可以尝试破解程序的克隆来解决此问题;我不知道这是否足够。

      对于您暗示有相同问题的“其他 Stata 软件包”,除了可能出于相同原因而出现此问题外,无法进行具体评论。因子变量于 2009 年在 Stata 11 (see here for documentation) 中引入,旧程序未经修改不允许使用它们。

      一般来说,我会在 Statalist 上问这样的问题。该程序很可能已被某些不同的程序取代。

      如果您在 Internet 上发现一个没有帮助文件的 Stata 程序,就像这里的情况一样,这通常表明该程序是 ad hoc 编写的并且没有得到维护。在这种情况下,也很明显,该程序自 Stata 11 以来的 6 年没有更新。

      正如您所暗示的,您也可以自己创建交互变量。我认为没有人编写过一个真正通用的工具来自动化它:(自 2009 年以来)因子变量表示法的复杂替代方案毫无意义。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-02
        • 1970-01-01
        • 2014-06-11
        • 2022-01-24
        相关资源
        最近更新 更多