Hello everyone,
I’m working on merging two datasets from the same source in Stata but encountering issues with the merge process. Here are the details:
Here’s a snippet of my Stata data set that I obtain from my merge 1:n. As we can see, both rendered outputs are the same, but still not merged between them:
I should have the 4,000,414 observations from my master data, but that is not the case
Here is a sample of my master dataset:
Here is a sample of my using dataset:
I hope you can provide me some help on that please. I am really stuck since a while and do not know why.
Thanks a lot in advance!
I’m working on merging two datasets from the same source in Stata but encountering issues with the merge process. Here are the details:
- Objective: I want to merge a cleaned dataset (all_cars_cleaned_cardesc15-19_fordemand.dta) with another dataset (DGT_data_with_postal_code.dta) primarily on the postal code.
- Datasets:
- Cleaned Dataset: Contains variables like brand, model_dup_original, fuel, engine_cap, etc.
- Other Dataset: Includes postal codes and other vehicle details.
- Steps Taken:
- Cleaned and prepared both datasets.
- Renamed variables for consistency.
- Dropped duplicates using duplicates drop, to ensure to have my "1" part for subsequent merge
- Used merge 1:n to combine datasets.
- Issue: The merge results are not as expected. There seem to be discrepancies or unmatched records.
Here’s a snippet of my Stata data set that I obtain from my merge 1:n. As we can see, both rendered outputs are the same, but still not merged between them:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float fec_tramitacion_date str23 brand str2 fuel long engine_cap double fiscal_power long(weight_max muni_code) double kw_itv int co2 str17 emission str4 ev_type str26 model_dup_original long postal_code byte merge_or_not . "FIAT" "1" 1956 13.14 2100 17015 103 144 "EURO 6W" "" "FIAT 500X" . 1 . "" "1" 1956 13.140000343322754 2100 17015 103 144 "" "" "FIAT 500X" 17820 2 end format %td fec_tramitacion_date label values merge_or_not _merge label def _merge 1 "Master only (1)", modify label def _merge 2 "Using only (2)", modify
I should have the 4,000,414 observations from my master data, but that is not the case
Code:
Result Number of obs
-----------------------------------------
Not matched 15,331,702
from master 3,914,756 (merge_or_not==1)
from using 11,416,946 (merge_or_not==2)
Matched 63,001 (merge_or_not==3)
-----------------------------------------
Here is a sample of my master dataset:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float fec_matricula_date str29 brand str26 model_dup_original str2 fuel long engine_cap float fiscal_power long(weight_max muni_code postal_code) str2 vehicle_type str1 vehicle_origin double kw_itv int co2 str9 emission str4 ev_type -13355 "CITROEN" "B2" "0" 1452 10.99 1300 40904 40420 "40" "3" 14.72 . "" "" -12687 "CITROEN" "5CV TYPE C" "0" 855 8 900 28115 28224 "40" "0" 8.2 . "ND" "" -12211 "ROCHET SCHNEIDER" "25000" "0" 2603 15.6 2480 8078 8614 "40" "3" 24 . "ND" "" -11801 "ERSKINE" "MODEL 50 SEDAN" "0" 2394 17.45 1760 50298 50800 "40" "3" 29.82 . "" "" -10755 "FORD" "A" "0" 1200 .18 0 11020 11401 "40" "0" 0 . "" "" end format %td fec_matricula_date
Here is a sample of my using dataset:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str8(fec_matricula fec_tramitacion) str23 brand str22 model_dup_original str1 fuel long engine_cap double fiscal_power long(weight_max muni_code) double kw_itv int co2 str17 emission str4(power ev_type) "02012015" "05012015" "MAZDA" "MAZDA 3" "0" 1998 13.3 1800 5019 88 119 "EURO 5" "0" "" "02012015" "07012015" "RENAULT" "MEGANE" "0" 1197 9.78 1787 47186 97 124 "EURO 5J" "0" "" "02012015" "08012015" "MERCEDES" "V 220 CDI" "1" 2143 13.88 3050 17066 120 149 "EURO 5-K" "0" "" "05012015" "09012015" "MERCEDES" "V 250 BLUETEC" "1" 2143 13.88 3050 33066 140 157 "EURO 6W" "0" "" "02012015" "09012015" "VOLKSWAGEN" "GOLF" "1" 1598 11.64 1820 47186 77 99 "ND" "0" "" end
I hope you can provide me some help on that please. I am really stuck since a while and do not know why.
Thanks a lot in advance!

Comment