当我尝试在Stata中设置每月动态面板数据时:
clear all
drop _all
cls
scalar mnpe = 3
scalar cssize = 6
scalar ldataset = mnpe * cssize
set obs `=ldataset'
//Define variables for the Timewindow to be analized
scalar tstart = 480 //From: 2000/January
scalar tend = `=tstart' + `=cssize' //To : 2000/June
//Generate id and time for the Dynamic Panel
egen id = seq(), block(`=cssize')
egen time = seq(), from(`=tstart') to(`=tend')
format %tm time //Period definition tm: monthly
//Declare THE Dynamic Panel
tsset id time, monthly //Period definition : monthly
//Generate endogenous & exogenous variables
gen y = rnormal(5,1)
gen x1 = rnormal(10,1)
//List them up, by id
list, sepby(id)
xtline x1, tlabel(#3) overlay
我遇到了以下丢失的时间数据:
+-----------------------------------+
| id time y x1 |
|-----------------------------------|
1. | 1 2000m1 3.821689 10.56352 |
2. | 1 2000m2 4.572973 12.12826 |
3. | 1 2000m3 5.798653 8.558586 |
4. | 1 2000m4 8.021777 12.33319 |
5. | 1 2000m5 3.917288 9.168543 |
6. | 1 2000m6 4.780022 10.94 |
|-----------------------------------|
7. | 2 2000m1 4.70402 9.462132 |
8. | 2 2000m2 4.164953 11.23561 |
9. | 2 2000m3 7.09228 10.03154 |
10. | 2 2000m4 4.429367 10.36254 |
11. | 2 2000m5 3.171889 9.664372 |
12. | 2 2000m7 4.455237 10.33883 |
|-----------------------------------|
13. | 3 2000m1 3.643499 12.20954 |
14. | 3 2000m2 4.201683 9.507583 |
15. | 3 2000m3 4.809181 11.44474 |
16. | 3 2000m4 5.51936 10.25571 |
17. | 3 2000m6 5.279757 9.676065 |
18. | 3 2000m7 5.379889 11.40392 |
+-----------------------------------+
如您所见,还有几个月缺失。不确定到底发生了什么,尽管我不认为这是由于夏令时造成的差异。
答案 0 :(得分:1)
没有毛刺-标量tend
中的值是错误的。
您需要从中减去1
:
clear
scalar mnpe = 3
scalar cssize = 6
scalar ldataset = mnpe * cssize
set obs `=ldataset'
scalar tstart = 480
scalar tend = `=tstart' + `=cssize' - 1
egen id = seq(), block(6)
egen time = seq(), from(`=tstart') to(`=tend')
format %tm time
这将产生所需的结果:
list, sepby(id)
+-------------+
| id time |
|-------------|
1. | 1 2000m1 |
2. | 1 2000m2 |
3. | 1 2000m3 |
4. | 1 2000m4 |
5. | 1 2000m5 |
6. | 1 2000m6 |
|-------------|
7. | 2 2000m1 |
8. | 2 2000m2 |
9. | 2 2000m3 |
10. | 2 2000m4 |
11. | 2 2000m5 |
12. | 2 2000m6 |
|-------------|
13. | 3 2000m1 |
14. | 3 2000m2 |
15. | 3 2000m3 |
16. | 3 2000m4 |
17. | 3 2000m5 |
18. | 3 2000m6 |
+-------------+