【问题标题】:Using xtreg with unique identifier that includes letters使用带有包含字母的唯一标识符的 xtreg
【发布时间】:2015-11-21 19:26:50
【问题描述】:

我正在尝试使用我的面板数据集进行回归。

我想说明状态固定效应,并尝试使用一些奇怪的标识符。

我的分析单位是状态中的实用程序,为此我创建了一个由实用程序 ID 和状态组成的复合唯一标识符。

因此,我的数据如下所示:

unique_id     ownership   amiratio   popd
10570AL       REC         .45        3430
4032CA        IOU         .85        4350

但是,xtset 不喜欢标识符中的字母。

我的预期回归如下所示:

xtreg amiratio ownership ownership#popd, fe vce(cluster i.state) 

如何将我的唯一 ID 转换为正确的形式来运行此回归?

【问题讨论】:

    标签: panel stata


    【解决方案1】:

    encode 命令可用于此目的:

    clear
    input str10 unique_id str3 ownership amiratio popd
    10570AL REC .45 3430
    4032CA IOU .85 4350
    end
    
    encode unique_id, generate(wanted)
    

    这会将字符串变量转换为数值标签与字符串匹配的数字:

    list unique_id wanted, abbreviate(10)
    
         +---------------------+
         | unique_id    wanted |
         |---------------------|
      1. |   10570AL   10570AL |
      2. |    4032CA    4032CA |
         +---------------------+
    
    list unique_id wanted, abbreviate(10) nolabel
    
         +--------------------+
         | unique_id   wanted |
         |--------------------|
      1. |   10570AL        1 |
      2. |    4032CA        2 |
         +--------------------+
    

    xtsetwanted 一起使用将与unique_id 形成对比:

    xtset unique_id
    string variables not allowed in varlist;
    unique_id is a string variable
    r(109);
    
    xtset wanted
         panel variable:  wanted (balanced)
    

    【讨论】:

      猜你喜欢
      • 2013-09-09
      • 1970-01-01
      • 2010-11-01
      • 2020-09-11
      • 1970-01-01
      • 2019-10-22
      • 2016-08-06
      • 2011-05-30
      • 2022-07-19
      相关资源
      最近更新 更多