面板数据新手在这里!我在Stata中有以下格式的数据:
Name Company1 Company2 Company3 Company4 Company5 Company6
1985 6.0781 2.4766 1.4258 2.6508 13.2083
1986 6.4844 3.0938 2.1953 3.1351 15.7917
1987 10.1563 .2769 5.7109 3.6406 4.4058 15.5833
1988 10.4688 .4219 5.125 3.75 3.6767 8.1667
1989 11.0625 .4289 5.4453 3.9844 3.7288 10.25
1990 11.6875 .7206 6.875 5.6406 5.1974 8.6667
1991 13.6563 1.4863 10.1406 8.9687 5.6869 5.7083
1992 13.75 2.5522 12.2187 13 6.4681 10.875
1993 16.0938 2.6172 10.3437 16.4375 7.0826 13.6667
1994 16.3125 2.5313 9.9375 14 8.7387 12.125
1995 15.8125 3.9766 14.4375 12.5 8.8324 13.2083
我知道我通常不得不以某种方式使用reshape
命令,但我不确定如何。我试试
reshape wide Name, i(Name) j(Name)
显然失败了
(note: j = 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2
> 007 2008 2009 2010 2011 2012 2013 2014 2015)
no variables defined
r(111);
CompanyNumber(Number1,2,3,4,5,6)将是面板数据中使用的ID,年份将分别是每个公司的时间。
任何想法如何reshape
或者这些数据是否采用适当的面板数据格式?
我的数据在Stata中的实际情况如何
我尝试运行nick cox代码时遇到的错误:
答案 0 :(得分:1)
你的沙箱数据有隐含的缺失值,所以前两行被省略了我读到的方式。我认为这是偶然的。正如@Roberto Ferrer清楚解释的那样,这是一个(完全标准的)reshape long
。
clear
input Name Company1 Company2 Company3 Company4 Company5 Company6
1985 6.0781 2.4766 1.4258 2.6508 13.2083
1986 6.4844 3.0938 2.1953 3.1351 15.7917
1987 10.1563 .2769 5.7109 3.6406 4.4058 15.5833
1988 10.4688 .4219 5.125 3.75 3.6767 8.1667
1989 11.0625 .4289 5.4453 3.9844 3.7288 10.25
1990 11.6875 .7206 6.875 5.6406 5.1974 8.6667
1991 13.6563 1.4863 10.1406 8.9687 5.6869 5.7083
1992 13.75 2.5522 12.2187 13 6.4681 10.875
1993 16.0938 2.6172 10.3437 16.4375 7.0826 13.6667
1994 16.3125 2.5313 9.9375 14 8.7387 12.125
1995 15.8125 3.9766 14.4375 12.5 8.8324 13.2083
end
reshape long Company, i(Name)
rename (Company Name _j) (whatever year company)
sort company year
list , sepby(company)
+---------------------------+
| year company whatever |
|---------------------------|
1. | 1987 1 10.1563 |
2. | 1988 1 10.4688 |
3. | 1989 1 11.0625 |
4. | 1990 1 11.6875 |
5. | 1991 1 13.6563 |
6. | 1992 1 13.75 |
7. | 1993 1 16.0938 |
8. | 1994 1 16.3125 |
9. | 1995 1 15.8125 |
|---------------------------|
10. | 1987 2 .2769 |
11. | 1988 2 .4219 |
12. | 1989 2 .4289 |
13. | 1990 2 .7206 |
14. | 1991 2 1.4863 |
15. | 1992 2 2.5522 |
16. | 1993 2 2.6172 |
17. | 1994 2 2.5313 |
18. | 1995 2 3.9766 |
|---------------------------|
19. | 1987 3 5.7109 |
20. | 1988 3 5.125 |
21. | 1989 3 5.4453 |
22. | 1990 3 6.875 |
23. | 1991 3 10.1406 |
24. | 1992 3 12.2187 |
25. | 1993 3 10.3437 |
26. | 1994 3 9.9375 |
27. | 1995 3 14.4375 |
|---------------------------|
28. | 1987 4 3.6406 |
29. | 1988 4 3.75 |
30. | 1989 4 3.9844 |
31. | 1990 4 5.6406 |
32. | 1991 4 8.9687 |
33. | 1992 4 13 |
34. | 1993 4 16.4375 |
35. | 1994 4 14 |
36. | 1995 4 12.5 |
|---------------------------|
37. | 1987 5 4.4058 |
38. | 1988 5 3.6767 |
39. | 1989 5 3.7288 |
40. | 1990 5 5.1974 |
41. | 1991 5 5.6869 |
42. | 1992 5 6.4681 |
43. | 1993 5 7.0826 |
44. | 1994 5 8.7387 |
45. | 1995 5 8.8324 |
|---------------------------|
46. | 1987 6 15.5833 |
47. | 1988 6 8.1667 |
48. | 1989 6 10.25 |
49. | 1990 6 8.6667 |
50. | 1991 6 5.7083 |
51. | 1992 6 10.875 |
52. | 1993 6 13.6667 |
53. | 1994 6 12.125 |
54. | 1995 6 13.2083 |
+---------------------------+