regression - 如何在合作伙伴的变量 X 上回归一个人的 Y?
问题描述
我调查了家庭内部/伴侣之间的某些影响。我有paneldata
几个变量(人年)和一个合作伙伴 ID。我想回归一个人对其伴侣的因变量值的结果。我不知道如何在 Stata 中执行此规范。
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(year id pid y x)
1 1 3 9 2
2 1 3 10 4
3 1 . 11 6
1 2 4 20 2
2 2 4 21 6
3 2 3 22 7
1 3 1 25 5
2 3 1 30 10
3 3 2 35 15
1 4 2 20 4
2 4 2 30 6
3 4 . 40 8
end
* pooled regression
reg y x
* fixed effects regression
xtset year id
xtreg y x, fe
我可以做汇集和固定效应回归。但即使对于汇总/简单回归,我如何将某人的结果回归到其他人的自变量?
实际上对于第 1 个人,我需要在 5/10/ 2011 年 9 月 10 日回归。等等。
- 第 2 人:2015 年 4 月 6 日 20/21/22 回归
- 第 3 人:在 2/4/7 回归 25/30/35
- 第 4 人:在 2/6/20/30/40 回归。
想法:如果函数中没有选项regress
,我想我可以为我拥有的每个自变量创建新变量并命名它x_partner
。在这个例子x_partner
中应该包含 5,10,.,4,6,15,2,4,7,2,6,。但我仍然不知道如何实现这一目标。
bysort id (year): egen x_partner = x[pid] // rough idea
解决方案
粗略的想法是行不通的。egen
需要指定其自己的函数之一,仅此一项就使语法非法。
但这里的本质是查找合作伙伴的值并放入与每个标识符对齐的新变量。
感谢您使用dataex
.
rangestat
来自社区贡献的命令 SSC 允许使用单线解决方案。考虑
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(year id pid y x)
1 1 3 9 2
2 1 3 10 4
3 1 . 11 6
1 2 4 20 2
2 2 4 21 6
3 2 3 22 7
1 3 1 25 5
2 3 1 30 10
3 3 2 35 15
1 4 2 20 4
2 4 2 30 6
3 4 . 40 8
end
ssc install rangestat
rangestat wanted_y=y wanted_x=x if !missing(id, pid), interval(id pid pid) by(year)
list, sepby(id)
+-------------------------------------------------+
| year id pid y x wanted_y wanted_x |
|-------------------------------------------------|
1. | 1 1 3 9 2 25 5 |
2. | 2 1 3 10 4 30 10 |
3. | 3 1 . 11 6 . . |
|-------------------------------------------------|
4. | 1 2 4 20 2 20 4 |
5. | 2 2 4 21 6 30 6 |
6. | 3 2 3 22 7 35 15 |
|-------------------------------------------------|
7. | 1 3 1 25 5 9 2 |
8. | 2 3 1 30 10 10 4 |
9. | 3 3 2 35 15 22 7 |
|-------------------------------------------------|
10. | 1 4 2 20 4 20 2 |
11. | 2 4 2 30 6 21 6 |
12. | 3 4 . 40 8 . . |
+-------------------------------------------------+
推荐阅读
- robotframework - Robot Framework,即使出现任何故障,如何继续测试用例
- wpf - 为子网格内容禁用 WPF ScrollViewer 滚动条
- html - 在线共享点(Office 365):CEWP
- java - 如何将大文件上传到 GCP 云存储?
- c# - 获取连接到远程服务器端口的所有客户端
- android - 当按下后退按钮时,我的应用程序会关闭最近的应用程序
- ruby-on-rails - 当我在模型中添加自定义验证时,RSpec 中的模型验证失败
- java - 如何在java中产生编译代码分段错误?
- c# - tfs 2018通过c#上传流程模板
- powershell - 使用 powershell 替换 .dtsConfig 中的值