This exercise is to reproduce regression results Feenstra (1988a). To complete the exercise, the files “car_7990.dta” and “truck_7990.dta” should be stored in Chapter-8.
Documentation
Data Description for Feenstra (1988a):
car.dta: This STATA file contains car’s various characteristics, such as weight (wght), width (wdth), height (hght), horse power (hs), four-wheel (four), transmission (tran), power steering (ps) and air condition (ac) for 1979-1990. It also includes each model’s sales (quan) and price.
truck.dta: This STATA file contains truck’s various characteristics, such as weight (wght), width (wdth), height (hght), horse power (hs), four-wheel (four), transmission (tran), power steering (ps) and air condition (ac) for 1979-1990. It also includes each model’s sale (quan) and price, though sales are missing after 1985.
Exercise 1
Run the programs pindex_c.do, pindex_t.do, unit_value.do to reproduce the price indexes and unit-values for cars and trucks in Table 8.3. What formula is used for the price indexes, and how does this differ from the unit-values?
# A tibble: 12 × 2
year uvalue
<dbl> <dbl>
1 79 4794.
2 80 4937.
3 81 6314.
4 82 6426.
5 83 6134.
6 84 6247.
7 85 6250.
8 86 NaN
9 87 NaN
10 88 NaN
11 89 NaN
12 90 NaN
Exercise 2
Run the program car_reg.do to reproduce the column (1) in Table 8.4, and the program truck_reg.do to reproduce column (2). What weights are being used in the regression, and how does this affect the results?
# function to avoid repeating the same code four timesreshape_estimates <-function(fit, vehicle, term_prefix, term_mappings) {tidy(fit) %>%filter(term %in%paste0(term_prefix, 1:8)) %>%mutate(term =case_when( term ==paste0(term_prefix, "1") ~ term_mappings[1], term ==paste0(term_prefix, "2") ~ term_mappings[2], term ==paste0(term_prefix, "3") ~ term_mappings[3], term ==paste0(term_prefix, "4") ~ term_mappings[4], term ==paste0(term_prefix, "5") ~ term_mappings[5], term ==paste0(term_prefix, "6") ~ term_mappings[6], term ==paste0(term_prefix, "7") ~ term_mappings[7], term ==paste0(term_prefix, "8") ~ term_mappings[8] ) ) %>%select(term, estimate, std.error) %>%pivot_longer(cols =c(estimate, std.error), names_to ="stat",values_to ="value" ) %>%mutate(stat =if_else(stat =="estimate", "Estimate", "Std. Error"),value =round(value, 3) ) %>%rename(!!sym(vehicle) := value)}car_vars <-c("Weight (tons)", "Width (feet)", "Height (feet)", "Horsepower (100)","Transmission (5-speed or auto)", "Power steering", "Air conditioning", "Constant")truck_vars <-c("Weight (tons)", "Width (feet)", "Height (feet)", "Horsepower (100)","Transmission (5-speed or auto)", "Power steering", "Four-wheel drive", "Constant")ordered_vars <-unique(c(car_vars, truck_vars))ordered_vars <-c("Constant", ordered_vars[ordered_vars !="Constant"])table_84_1 <-reshape_estimates(fit2, "Car", "c", car_vars) %>%full_join(reshape_estimates(fit4, "Truck", "b", truck_vars)) %>%# mutate term to factor + keep Constant at the beginningmutate(term =factor(term, levels = ordered_vars) ) %>%arrange(term)colnames(table_84_1) <-c("Variable", "Statistic", "Car", "Truck")kable(table_84_1)
Variable
Statistic
Car
Truck
Constant
Estimate
6.328
7.558
Constant
Std. Error
0.583
0.539
Weight (tons)
Estimate
0.025
0.438
Weight (tons)
Std. Error
0.121
0.059
Width (feet)
Estimate
0.357
0.077
Width (feet)
Std. Error
0.108
0.110
Height (feet)
Estimate
-0.063
-0.042
Height (feet)
Std. Error
0.055
0.047
Horsepower (100)
Estimate
0.690
0.240
Horsepower (100)
Std. Error
0.085
0.108
Transmission (5-speed or auto)
Estimate
0.143
0.034
Transmission (5-speed or auto)
Std. Error
0.024
0.025
Power steering
Estimate
0.058
0.093
Power steering
Std. Error
0.027
0.035
Air conditioning
Estimate
0.147
NA
Air conditioning
Std. Error
0.033
NA
Four-wheel drive
Estimate
NA
0.228
Four-wheel drive
Std. Error
NA
0.027
Exercise 3
Pooling car and truck data, run system_7985.do to reproduce columns (3) and (4) in Table 8.4 with the constraints specified in equation (8.22). How are these constraints built into the program for the nonlinear regression?
table_84_2 <-tidy(fit2) %>%select(term, estimate, std.error) %>%mutate(vehicle =substr(term, 1, 1),vehicle =case_when( vehicle =="c"~"car", vehicle =="d"~"truck",TRUE~"Exclude" ) ) %>%filter(vehicle !="Exclude") %>%mutate(term =case_when( term =="c1"| term =="d1"~"Weight (tons)", term =="c2"| term =="d2"~"Width (feet)", term =="c3"| term =="d3"~"Height (feet)", term =="c4"| term =="d4"~"Horsepower (100)", term =="c5"| term =="d5"~"Transmission (5-speed or auto)", term =="c6"| term =="d6"~"Power steering", term =="c7"~"Air conditioning", term =="d7"~"Four-wheel drive", term =="c8"| term =="d8"~"Constant",TRUE~"Exclude" ) ) %>%filter(term !="Exclude") %>%pivot_longer(cols =c(estimate, std.error), names_to ="stat") %>%pivot_wider(names_from ="vehicle", values_from ="value") %>%mutate_if(is.numeric, ~round(., 3)) %>%mutate(term =factor(term, levels =c("Constant", "Weight (tons)", "Width (feet)", "Height (feet)","Horsepower (100)", "Transmission (5-speed or auto)", "Power steering","Air conditioning", "Four-wheel drive" )),stat =if_else(stat =="estimate", "Estimate", "Std. Error") ) %>%arrange(term)colnames(table_84_2) <-c("Variable", "Statistic", "Car", "Truck")kable(table_84_2)
Variable
Statistic
Car
Truck
Constant
Estimate
5.839
6.630
Constant
Std. Error
0.862
0.765
Weight (tons)
Estimate
0.049
0.476
Weight (tons)
Std. Error
0.131
0.117
Width (feet)
Estimate
0.391
0.212
Width (feet)
Std. Error
0.138
0.142
Height (feet)
Estimate
-0.062
-0.027
Height (feet)
Std. Error
0.061
0.074
Horsepower (100)
Estimate
0.810
0.244
Horsepower (100)
Std. Error
0.104
0.152
Transmission (5-speed or auto)
Estimate
0.178
0.053
Transmission (5-speed or auto)
Std. Error
0.036
0.036
Power steering
Estimate
0.069
0.058
Power steering
Std. Error
0.030
0.064
Air conditioning
Estimate
0.157
NA
Air conditioning
Std. Error
0.036
NA
Four-wheel drive
Estimate
NA
0.297
Four-wheel drive
Std. Error
NA
0.057
Exercise 4
Run the programs unit_quality.do, qindex_c.do, qindex_t.do to reproduce the quality indexes and unit-qualities for cars and trucks in Table 8.3. What formula is used for the quality of each model and the quality indexes, and how does this differ from the unit-quality?
Pooling car and truck data, run system_nocom.do and system_wcon.do to reproduce columns (1) - (4) in Table 8.5, with constraints specified in equation (8.22).
I need to replace variables such as “c1” with “Weight (tons)” to replicate Table 3.5. I can do this by looking at the coefficients of the variables in the non-linear regression function.
# function to avoid repeating the same code four timesreshape_estimates <-function(fit, vehicle, term_prefix, term_mappings) {tidy(fit) %>%filter(term %in%paste0(term_prefix, 1:8)) %>%mutate(term =case_when( term ==paste0(term_prefix, "1") ~ term_mappings[1], term ==paste0(term_prefix, "2") ~ term_mappings[2], term ==paste0(term_prefix, "3") ~ term_mappings[3], term ==paste0(term_prefix, "4") ~ term_mappings[4], term ==paste0(term_prefix, "5") ~ term_mappings[5], term ==paste0(term_prefix, "6") ~ term_mappings[6], term ==paste0(term_prefix, "7") ~ term_mappings[7], term ==paste0(term_prefix, "8") ~ term_mappings[8] ) ) %>%select(term, estimate, std.error) %>%pivot_longer(cols =c(estimate, std.error), names_to ="stat",values_to ="value" ) %>%mutate(stat =if_else(stat =="estimate", "Estimate", "Std. Error"),value =round(value, 3) ) %>%rename(!!sym(vehicle) := value)}car_vars <-c("Weight (tons)", "Width (feet)", "Height (feet)", "Horsepower (100)","Transmission (5-speed or auto)", "Power steering", "Air conditioning", "Constant")truck_vars <-c("Weight (tons)", "Width (feet)", "Height (feet)", "Horsepower (100)","Transmission (5-speed or auto)", "Power steering", "Four-wheel drive", "Constant")ordered_vars <-unique(c(car_vars, truck_vars))ordered_vars <-c("Constant", ordered_vars[!ordered_vars %in%"Constant"])table_85 <-reshape_estimates(fit2, "cars", "c", car_vars) %>%full_join(reshape_estimates(fit2, "trucks", "d", truck_vars)) %>%full_join(reshape_estimates(fit4, "cars", "c", car_vars),by =c("term", "stat") ) %>%full_join(reshape_estimates(fit4, "trucks", "d", truck_vars),by =c("term", "stat") ) %>%mutate(term =factor(term, levels = ordered_vars) ) %>%arrange(term)colnames(table_85) <-c("Variable", "Statistic", "Cars (No Con)", "Trucks (No Con)","Cars (W Con)", "Trucks (W Con)")kable(table_85)