1

I have dataframe mds that looks like this:

> mds
county_code     2000q1    2000q2    2000q3    2000q4
 452              80        92        99       101
 453              81        93        101      102
 454              82        94        102      103
 455              83        95        103      104

I'd like to stack mds, so that the result looks like this:

county_code     quarter     value 
 452            2000q1        80
 452            2000q2        92
 452            2000q3        99
 452            2000q4        101
 453            2000q1        81
 453            2000q2        93
 453            2000q3        101
 453            2000q4        102 
 454            2000q1        82
 454            2000q2        94
 454            2000q3        102
 454            2000q4        103
 455            2000q1        83
 455            2000q2        95
 455            2000q3        103
 455            2000q4        104

So far, I've tried stack(md), but this stacks county_code in the same column as the values associated with each year and county. I've also tried stack(select(mds, contains("q")), but this loses the county code information.

So my question is -- how can I stack only a portion of a panel dataset?

svenkatesh
  • 1,152
  • 2
  • 10
  • 25

0 Answers0