Dear Statalist,
Is any way that I could merge cross-section data into panel data set based on their stock code? Here is my sample of data:
Cross-section data: file1
Panel data set: file 2
open the file 1 and
Code: merge m:m StockCode using "C:\Users\Jessie\Desktop\Data\file 2.dta". I have tried the merge function using this code which doesn't allow the data to automatically fill up the blank sheet. Appreciate it if anyone could help. And I expect the result below.
turns into:
Is any way that I could merge cross-section data into panel data set based on their stock code? Here is my sample of data:
Cross-section data: file1
StockCode | Stock Short Name | Industry Code C | ||||
000001 | PAYH |
|
||||
000002 | WKA | K70 | ||||
StockCode | Enddate | DirectorNumber |
000001 | 2014-12-31 | 15 |
000001 | 2015-12-31 | 14 |
000001 | 2016-12-31 | 11 |
000001 | 2017-12-31 | 14 |
000001 | 2018-12-31 | 14 |
000001 | 2019-12-31 | 13 |
000001 | 2020-12-31 | 15 |
000002 | 2014-12-31 | 11 |
000002 | 2015-12-31 | 11 |
000002 | 2016-12-31 | 11 |
000002 | 2017-12-31 | 11 |
000002 | 2018-12-31 | 11 |
000002 | 2019-12-31 | 10 |
000002 | 2020-12-31 | 11 |
Code: merge m:m StockCode using "C:\Users\Jessie\Desktop\Data\file 2.dta". I have tried the merge function using this code which doesn't allow the data to automatically fill up the blank sheet. Appreciate it if anyone could help. And I expect the result below.
turns into:
StockCode | Enddate | DirectorNumber | Stock Short name | Industry Code |
1 | 2014/12/31 | 15 | PAYH | J66 |
1 | 2015/12/31 | 14 | PAYH | J66 |
1 | 2016/12/31 | 11 | PAYH | J66 |
1 | 2017/12/31 | 14 | PAYH | J66 |
1 | 2018/12/31 | 14 | PAYH | J66 |
1 | 2019/12/31 | 13 | PAYH | J66 |
1 | 2020/12/31 | 15 | PAYH | J66 |
2 | 2014/12/31 | 11 | WKA | K70 |
2 | 2015/12/31 | 11 | WKA | K70 |
2 | 2016/12/31 | 11 | WKA | K70 |
2 | 2017/12/31 | 11 | WKA | K70 |
2 | 2018/12/31 | 11 | WKA | K70 |
2 | 2019/12/31 | 10 | WKA | K70 |
2 | 2020/12/31 | 11 | WKA | K70 |
Comment