Hi Statalist community,
I’m reaching out for assistance with a merging issue. I am trying to merge two datasets that appear to be very similar at a glance. However, I’m struggling to get a proper merge due to a type mismatch issue, specifically with the variable litres.
Below is a sample of my attempted merge, generated using -dataex-:
When I browse through the datasets in Stata, litres appear identical across both files. However, during the merge, Stata adjusts the variable formats. Here’s my merge code:
Here is my code:
Here is what I obtained at the end of the -merge- process:
Could anyone help me with that? I tried -recast- and -round()-, but do not work neither.
Thank you very much in advance.
I’m reaching out for assistance with a merging issue. I am trying to merge two datasets that appear to be very similar at a glance. However, I’m struggling to get a proper merge due to a type mismatch issue, specifically with the variable litres.
Below is a sample of my attempted merge, generated using -dataex-:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float ym_date str29 make str31 model str22 fueltype double litres str10 powertraintype byte _merge 692 "HONDA" "JAZZ" "0" 1.2999999523162842 "COMBUSTION" 1 692 "HONDA" "JAZZ" "0" 1.2999999523162842 "COMBUSTION" 1 692 "HONDA" "JAZZ" "0" 1.2999999523162842 "COMBUSTION" 1 692 "HONDA" "JAZZ" "0" 1.2999999523162842 "COMBUSTION" 1 692 "HONDA" "JAZZ" "0" 1.3 "COMBUSTION" 2 end format %tm ym_date label values _merge _merge label def _merge 1 "Master only (1)", modify label def _merge 2 "Using only (2)", modify
Here is my code:
Code:
// Car Prices ----------------------------------------------------- use "${car_prices_15_20}/avg_prices_per_month_year_201501_202002.dta", clear /******************************************************************************** 2. Registrations data set preparing ********************************************************************************/ use "${dgt_data_cleaned}/dgt_all_cars_cleaned_201501_202002.dta", clear rename marca_itv make rename modelo_itv model rename cod_propulsion_itv fueltype rename categoría_vehículo_eléctrico powertraintype rename moyr_matricula ym_date merge m:1 ym_date make model litres fueltype powertraintype using "${car_prices_15_20}/avg_prices_per_month_year_201501_202002.dta"
Code:
. merge m:1 ym_date make model litres fueltype powertraintype using "`car_prices'" (variable litres was float, now double to accommodate using data's values) (variable fueltype was str2, now str22 to accommodate using data's values)
Thank you very much in advance.
Comment