【问题标题】:Stata adding variables complicatedStata添加变量复杂
【发布时间】:2021-07-29 13:56:11
【问题描述】:

我在 Stata 中有一个关于住房交易的数据集。现在我有一个数据集,其中每一行都是每笔交易持有期的一年。我正在寻找使用概率模型研究某年房屋被出售的概率。 dummy表示房子在当年是否售出,有1个正在售出。

现在我想在我的数据中添加另一个变量,其中包含该特定交易的持有期。这是我现在拥有的(一个例子):

dummy year bought current year
0 1620 1621
0 1620 1622
0 1620 1623
1 1620 1624
0 1622 1623
0 1622 1624
0 1622 1625
0 1622 1626
0 1622 1627
1 1622 1628

这就是我需要它变成的样子

dummy year bought current year holding period
0 1620 1621 4
0 1620 1622 4
0 1620 1623 4
1 1620 1624 4
0 1622 1623 6
0 1622 1624 6
0 1622 1625 6
0 1622 1626 6
0 1622 1627 6
1 1622 1628 6

【问题讨论】:

  • 数据中的每栋房子最终都卖了吗?数据中是否也有房屋 ID 变量?所以持有期只是每个房子ID中的max current year - min current year + 1
  • 是的,每套房子都卖了,而且确实有house id变量

标签: variables stata


【解决方案1】:

假设每个房子都有某种 id 变量:

egen sold_year = max(current_year), by(house_id)
gen holding_period = sold_year - year_bought

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    • 1970-01-01
    • 2021-03-19
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多