adrCoder
adrCoder

Reputation: 3275

Stata - panel data from column data

Panel data newbie here! I have data in Stata in the following format:

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

I know I normally have to use the reshape command somehow, but I am not sure how. I try

reshape wide Name, i(Name) j(Name)

which obviously fails

(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) will be the ID to be used in the panel data, and the year will be the time for each company respectively.

Any ideas how to reshape or w/e this data to be in proper panel data format?

How my data actually look like in Stata how my data really look in stata

The error I get when I try to run nick cox code: what i get when i execute nick cox code

Upvotes: 0

Views: 562

Answers (1)

Nick Cox
Nick Cox

Reputation: 37208

Your sandbox data has implicit missing values, so the first two lines get omitted the way I read this in. I take that as being incidental. As @Roberto Ferrer clearly explained, this is an (utterly standard) 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 |
     +---------------------------+

Upvotes: 1

Related Questions