Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Merging a yearly panel dataset with a quarterly panel dataset by creating a unique ID

    Dear All,

    I am attempting to merge the below data sets:
    Firm State Municipality Year
    1 1 1 2011
    1 1 1 2012
    1 1 2 2011
    1 1 2 2012
    2 1 3 2011
    and so on.
    Firm Year Quarter
    1 2011 3
    1 2011 12
    1 2012 3
    1 2012 12
    1 2013 3
    and so on.

    Both sets carry hundreds of observations.

    The only strategy I can think of is to expand the first dataset by two rows per observation, and somehow fill those automatically with "3" and "12". Then I could create a merge ID in both data sets as firm + year + quarter, which would be unique to the second, thus allowing for a m:1 merge.

    Do you have any thoughts on which command(s) would do the expansion/population for me, as it would be impossible to populate the quarters manually? Thanks also for commenting on whether sorting will play an important role.

  • #2
    Suppose your first dataset is named municip and your second dataset is named qtr. The following (untested) code might point you in a helpful direction.
    Code:
    use municip, clear
    joinby Firm Year using qtr
    You will find that this does automatically what you asked how to do manually.
    Last edited by William Lisowski; 21 Jul 2018, 09:41.

    Comment

    Working...
    X