Dear all:
I have data A stored in excel and need import A to stata , then merge A with dataset B that is already stored in stata.
data A in excel has two time variables : year (e.g. 2012) and quarter (Q1, Q2, …)
( I share a few observations for A , B as illustration. A is attached, B is below)
data B in stata has a datadate variable that is long and format %td
I generated two variables year and quarter from datadate (e.g., 2012, 4), both A and B has a firm identifier I can merge on.
My questions:
Rochelle
I have data A stored in excel and need import A to stata , then merge A with dataset B that is already stored in stata.
data A in excel has two time variables : year (e.g. 2012) and quarter (Q1, Q2, …)
( I share a few observations for A , B as illustration. A is attached, B is below)
data B in stata has a datadate variable that is long and format %td
I generated two variables year and quarter from datadate (e.g., 2012, 4), both A and B has a firm identifier I can merge on.
Code:
clear input str6 firmid long datadate float(cyear quarter) "008530" 18352 2010 1 "008530" 18443 2010 2 end format %td datadate
- how should I format the year and quarter in excel before I use import function in stata, so that I can merge A and B by firmID, year, quarter.
- Can I merge by firmID, year, quarter., or do I need to generate a timeid based on year and quarter , then merge by firmID, timeid
Rochelle
Comment