I would like to merge 2 datasets by range of dates and with an identifier (gvkey). So far, I have used "rangejoin" (ssc install) but I do not see options to manage unmatched data in each dataset (similar to the variable _merge create when using "merge 1:1 var using ...").
I would like to keep data in the using dataset "data3.dta" which includes the date (datadate) that I want to be within a certain range (linkdt) and (linkenddt). I do not wish to keep unmatched observations from the master dataset but I would like to browse and be able to see what has matched or not.
Master dataset: lnk.dta:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str6 gvkey int(linkdt linkenddt) "001000" 3969 6755 "001001" 8663 9708 "001002" 4731 4904 "001003" 8741 10820 "001004" 4497 . "001005" 4779 8431 "001007" 5022 6969 "001007" 6970 9037 "001008" 8637 10164 "001009" 8053 13221 "001010" -3532 760 "001010" 761 8945 "001011" 8480 13054 "001012" 6605 10955 "001013" 7014 18627 "001015" 8064 9800 "001016" 6543 10343 "001017" 4731 13208 "001018" 4930 6969 "001018" 6970 7733 "001019" 4731 10266 "001020" 4731 10322 "001021" 7592 14322 "001022" 4930 6086 "001022" 6087 8609 "001023" 8195 10505 "001024" 8602 9037 "001025" 4779 9209 "001026" 4731 6725 "001027" 2222 4165 "001028" 7972 11718 "001029" 8566 9435 "001030" 4779 5402 "001031" 91 2221 "001031" 2222 6299 "001034" 8811 17895 "001036" 8740 15126 "001036" 8740 15126 "001037" 7585 10464 "001038" 8630 16436 "001039" 3771 7273 "001040" -3652 760 "001040" 761 9435 "001042" 8207 9310 "001043" -3289 760 "001043" 761 8152 "001043" 8896 12192 "001043" 12393 14636 "001044" 2952 3833 "001045" -3652 760 "001045" 761 18996 "001045" 19701 . "001046" 8897 9282 "001047" 7894 8551 "001049" 5873 8181 "001050" 7637 . "001051" 1958 3287 "001052" 4839 6969 "001052" 6970 8490 "001054" 7944 12691 "001055" 9120 13755 "001056" 6390 17409 "001057" 1461 2586 "001057" 2587 2919 "001058" 913 9799 "001059" 4731 7760 "001061" 4839 6969 "001061" 6970 7609 "001062" 1855 . "001065" 8494 11522 "001066" 8796 9834 "001067" 913 2221 "001067" 2222 9127 "001069" 8691 9055 "001070" 2922 2951 "001070" 2952 7790 "001072" 4749 4836 "001072" 4837 10975 "001072" 13010 . "001073" 7738 13389 "001074" 3625 8400 "001075" 761 . "001076" 8343 12053 "001076" 11995 12053 "001076" 12054 18596 "001076" 12054 18596 "001076" 18597 18606 "001076" 18597 . "001077" 4930 6969 "001077" 6970 7578 "001078" -3652 760 "001078" 761 . "001079" 366 3317 "001079" 3318 6117 "001080" 1004 1459 "001080" 1460 5964 "001081" 10058 17465 "001081" 10058 17465 "001082" 8215 18870 "001083" 6573 7335 end format %td linkdt format %td linkenddt
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str6 gvkey double datadate "001000" 5843 "001000" 6209 "001000" 6574 "001001" 8765 "001001" 9131 "001001" 9496 "001003" 8765 "001003" 9131 "001003" 9527 "001003" 9892 "001003" 10257 "001003" 10623 "001003" 10988 "001004" 5629 "001004" 5995 "001004" 6360 "001004" 6725 "001004" 7090 "001004" 7456 "001004" 7821 "001004" 8186 "001004" 8551 "001004" 8917 "001004" 9282 "001004" 9647 "001004" 10012 "001004" 10378 "001004" 10743 "001004" 11108 "001004" 11473 "001004" 11839 "001004" 12204 "001004" 12569 "001004" 12934 "001004" 13300 "001004" 13665 "001004" 14030 "001004" 14395 "001004" 14761 "001004" 15126 "001004" 15491 "001004" 15856 "001004" 16222 "001004" 16587 "001004" 16952 "001004" 17317 "001004" 17683 "001004" 18048 "001004" 18413 "001004" 18778 "001004" 19144 "001004" 19509 "001004" 19874 "001004" 20239 "001004" 20605 "001004" 20970 "001004" 21335 "001004" 21700 "001004" 22066 "001005" 5782 "001005" 6148 "001005" 6513 "001005" 6878 "001005" 7243 "001005" 7609 "001005" 7974 "001006" 7851 "001006" 8216 "001007" 7212 "001007" 7578 "001007" 7943 "001007" 8308 "001007" 8673 "001007" 9039 "001008" 8917 "001008" 9282 "001008" 9647 "001009" 8339 "001009" 8704 "001009" 9070 "001009" 9435 "001009" 9800 "001009" 10165 "001009" 10531 "001009" 10896 "001009" 11261 "001009" 11626 "001009" 11992 "001009" 12357 "001009" 12722 "001010" 5843 "001010" 6209 "001010" 6574 "001010" 6939 "001010" 7304 "001010" 7670 "001010" 8035 "001010" 8400 "001010" 8765 "001010" 9131 end format %td datadate
0 Response to Merge 2 datasets by range of dates
Post a Comment