Hi Statalist Community,
I have a question to ask you, please.
I'm trying to clean up a string variable so that I can then merge two similar databases, the only thing that changes is the years between them. These are data sets on the average prices of cars put up for sale in Spain.
Here's what I do for year 2018:
Problem: no changes take place, whereas both in the Excel file, and through a "manual" inspection through stata, I observe that several excessive spaces exist, even though running the code above.
Here's an example:
or maybe this example, which is striking:
Could anyone give me a helping hand with that, please?
Thank you very much in advance!
Michael
I have a question to ask you, please.
I'm trying to clean up a string variable so that I can then merge two similar databases, the only thing that changes is the years between them. These are data sets on the average prices of cars put up for sale in Spain.
Here's what I do for year 2018:
Code:
//------ Local environment (adapt that to your current path) ------// * cd path global data "C:/Users/miduarte/Desktop/Ongoing_Projects/LEZ_Project/Data/car_prices_excel_15-19" cd "${data}" //------------// * * * 2018 Car Prices clear all import excel "${data}/car_prices_2018.xlsx", sheet("turismos") firstrow allstring case(lower) gen str type = "turismos" tempfile turismos_18 save `turismos_18', replace clear all import excel "${data}/car_prices_2018.xlsx", sheet("todoterreno") firstrow allstring case(lower) gen str type = "todoterreno" tempfile todoterreno_18 save `todoterreno_18', replace *Append with turismos clear* use `turismos_18', replace append using `todoterreno_18' replace modelotipo = itrim(trim(modelotipo))
Here's an example:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str141 modelotipo "4C 1.7 Tbi TCT / 1.75 6V 240" "4C SPIDER 1.7 Tbi TCT / 1.75 6V 240" "ALFA 33 1.3" "ALFA 33 1.5" "ALFA 33 1.7" end
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str16 marca str141 modelotipo "LAND ROVER" "Defender II 90 TDI SW / 2.5 Td5 Pick Up S / 2.5 Td5 SW E" "LAND ROVER" "Defender II 90 TDI SW Back" "LAND ROVER" "Defender II 90 TDI Techo Duro-Lona/T.D.Comerc.SW/Td5 Pick Up E" "LAND ROVER" "Defender II 90 TDI T. Duro Comerc." "LAND ROVER" "Defender II 90 TDI Tomb Rider" "LAND ROVER" "Defender II 110 Td5 2.5 SW E Com. / D. Cab Caja S / HCPU S Com" end
Could anyone give me a helping hand with that, please?
Thank you very much in advance!
Michael
Comment