Announcement

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

  • Matching values from a panel dataset to a cross-section dataset

    Dear all,
    I hope you can help me with what seems to be a rather simple issue that i cannot seem to figure out.

    I have a cross-section dataset that has information of 140 firms, ordered by id and year – it looks like this:
    Click image for larger version

Name:	Screenshot 2021-10-26 at 17.10.58.png
Views:	2
Size:	483.7 KB
ID:	1633348


    I need values of revenue (rev) and employment (empl) inserted to this dataset from a panel one, which has information of the same 140 firms, but arranged in a panel format for between 2011-2020 – it looks like this:

    Click image for larger version

Name:	Screenshot 2021-10-26 at 17.11.29.png
Views:	1
Size:	649.6 KB
ID:	1633349


    Is there a way to match or merge the dataset, somehow being able to insert rev and empl data from the panel one to the cross-section one - only for those years matching in the main 1st dataset? Any ideas? I am new to stata so this might be a rather stupid question but any help is appreciated!

    Thanks,
    Aydin
    Attached Files

  • #2
    Aydin, I think you may need to reformat "year" in the first dataset before implementing the merging.

    Code:
    use firstdata, clear
    destring year, replace
    
    merge 1:1 name year using seconddata
    drop if _merge == 2
    Last edited by Fei Wang; 26 Oct 2021, 09:54.

    Comment


    • #3
      Fei Wang thank you so much! yes, indeed I needed to destring the year variable!
      Now I was able to run the command, but the merged dataset doesn't actually have any values =)

      any thoughts?
      Click image for larger version

Name:	Screenshot 2021-10-26 at 17.45.20.png
Views:	1
Size:	208.6 KB
ID:	1633357

      Last edited by Aydin Yildirim; 26 Oct 2021, 09:46.

      Comment


      • #4
        Originally posted by Aydin Yildirim View Post
        Fei Wang thank you so much! yes, indeed I needed to destring the year variable!
        Now I was able to run the command, but the merged dataset doesn't actually have any values =)

        any thoughts?[ATTACH=CONFIG]n1633357[/ATTACH]
        Aydin, sorry that my previous codes have errors. Please refer to the updated codes in #2.

        Comment

        Working...
        X