Hi Statalist Community,
I need your help, please.
I have to predict the prices of certain models for which I don't have the prices. I have two databases, one with registrations, the other with prices. After matching, this is what I get. I'm particularly interested in -merged == 3- and -merged == 1-. For vehicles in -merged == 3-, all the prices are present.
What I'm trying to predict are the missing prices of cars from -merged == 1-. Roughly speaking, here is a small extract from my database (one line to get an idea and avoid overloading):
Two of these variables are good predictors of price: -engine_cap- and -power_kw-: if these two variables increase, the price will also increase, on average.
But, in my price database, I also have atypical models (HEV, FCEV, BEV, etc.). As a result, for these models, the cubic capacity is 0 (variable -engine_cap-), since they don't burn air like petrol- or diesel-fuelled cars. So I was thinking of using fixed effects to control this.
Thank you in advance for your help!
Michael
I need your help, please.
I have to predict the prices of certain models for which I don't have the prices. I have two databases, one with registrations, the other with prices. After matching, this is what I get. I'm particularly interested in -merged == 3- and -merged == 1-. For vehicles in -merged == 3-, all the prices are present.
Code:
. // merge process:
. merge m:1 id using `car_prices', generate(merged)
(variable model was str39, now str60 to accommodate using data's values)
(variable fuel was str1, now str4 to accommodate using data's values)
Result Number of obs
-----------------------------------------
Not matched 2,661,329
from master 2,659,732 (merged==1)
from using 1,597 (merged==2)
Matched 1,340,682 (merged==3)
-----------------------------------------
What I'm trying to predict are the missing prices of cars from -merged == 1-. Roughly speaking, here is a small extract from my database (one line to get an idea and avoid overloading):
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str23 brand str60 model str4 fuel long engine_cap double power_kw int co2 float fiscal_power str4 ev_type double price ‘ALFA ROMEO’ ‘146’ ‘1’ 1929 0 . 13.03 ‘’ . end
But, in my price database, I also have atypical models (HEV, FCEV, BEV, etc.). As a result, for these models, the cubic capacity is 0 (variable -engine_cap-), since they don't burn air like petrol- or diesel-fuelled cars. So I was thinking of using fixed effects to control this.
Code:
. tab ev_type
ev | Freq. Percent Cum.
------------+-----------------------------------
BEV | 13,589 6.00 6.00
FCEV | 2 0.00 6.01
HEV |201,511 89.05 95.05
PHEV | 10,873 4.80 99.86
REEV | 320 0.14 100.00
------------+-----------------------------------
Total |226,295 100.00
- This is what I do, and this is where I need your help, please. Do you think the following makes sense?
Code:
keep if merged == 1 | merged == 3
* Replace the gaps in the ev variable :
replace ev_type = ‘ combustion ’ if missing(ev_type) & (merged == 3)
encode ev_type, gen(ev_type_encode)
*
* Creation of a price log
gen ln_p = ln(price)
egen brand_model = group(brand model)
gen date = date(FEC_MATRICULA, ‘ DMY ’)
format date %td
*
*
* Step 1: Estimate the model and record the fixed effects
reghdfe ln_p engine_cap power_kw i.ev_type_encode, absorb(brand_model, savefe)
* Step 2: Generate predicted logarithmic prices for observed prices
predict yhat, xb
gen ln_p_hat = yhat + __hdfe1__
* Step 3: Calculate the average fixed effect for each brand model
egen efecto_fijo = mean(__hdfe1__), by(brand_model)
* Steps 4 and 5: Generate the predicted logarithmic prices for all observations
gen fixed_effect = __hdfe1__
replace fixed_effect = efecto_fijo if missing(fixed_effect)
gen ln_p_hat_all = yhat + fixed_effect
* Step 6: Generate the scatter plot
two-way scatter plot ln_p ln_p_hat_all if !missing(ln_p), ///
xline(0) yline(0) ///
title(‘Scatter plot of observed versus predicted logarithmic prices’) ///
xtitle(‘Predicted logarithmic prices’) ///
ytitle(‘Observed log prices’) ///
legend(off)
- Does anyone know why this sentence appears when I used my regression above?
note: 3.ev_type_encode omitted because of collinearity
Code:
reghdfe ln_p engine_cap power_kw i.ev_type_encode, absorb(brand_model, savefe)
Michael
