-
Notifications
You must be signed in to change notification settings - Fork 2
/
chapter8.qmd
4670 lines (3838 loc) · 132 KB
/
chapter8.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Chapter 8. Import Quotas and Export Subsidies
## Empirical exercise
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):
1. `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.
2. `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?
### Feenstra's code
#### pindex_c.do
```stata
clear
capture log close
log using Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\pindex_c.log,replace
use Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\car_7990,clear
keep year model type price quan
preserve
keep if year==80
keep model type price quan
ren price price_80
ren quan quan_80
sort model
save Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\car_80,replace
restore
sort model
merge model using Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\car_80
keep if _merge==3
drop _merge
sort year model
egen value_80=sum(price_80*quan_80), by(year)
egen value_cp=sum(price*quan_80),by(year)
gen lasp=value_cp/value_80
egen value_c=sum(price*quan), by(year)
egen value_cq=sum(price_80*quan), by(year)
gen pasp=value_c/value_cq
gen pindex=(lasp*pasp)^0.5
collapse (mean) pindex, by(year)
list
log close
```
Output:
```stata
. clear
. capture log close
. log using Z:\home\pacha\github\advanced-international-trade\first-edition\Chapte
> r-8\pindex_c.log,replace
(note: file Z:\home\pacha\github\advanced-international-trade\first-edition\Chapte
> r-8\pindex_c.log not found)
----------------------------------------------------------------------------------
name: <unnamed>
log: Z:\home\pacha\github\advanced-international-trade\first-edition\Chapt
> er-8\pindex_c.log
log type: text
opened on: 19 Jun 2024, 18:40:59
.
. use Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\ca
> r_7990,clear
. keep year model type price quan
.
. preserve
. keep if year==80
(260 observations deleted)
. keep model type price quan
. ren price price_80
. ren quan quan_80
. sort model
. save Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\c
> ar_80,replace
file Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\car
> _80.dta saved
. restore
.
. sort model
. merge model using Z:\home\pacha\github\advanced-international-trade\first-editio
> n\Chapter-8\car_80
(note: you are using old merge syntax; see [R] merge for new syntax)
variable model does not uniquely identify observations in the master data
. keep if _merge==3
(55 observations deleted)
. drop _merge
.
. sort year model
. egen value_80=sum(price_80*quan_80), by(year)
. egen value_cp=sum(price*quan_80),by(year)
. gen lasp=value_cp/value_80
.
. egen value_c=sum(price*quan), by(year)
. egen value_cq=sum(price_80*quan), by(year)
. gen pasp=value_c/value_cq
.
. gen pindex=(lasp*pasp)^0.5
.
. collapse (mean) pindex, by(year)
. list
+-----------------+
| year pindex |
|-----------------|
1. | 79 .9663 |
2. | 80 1 |
3. | 81 1.197522 |
4. | 82 1.289163 |
5. | 83 1.312988 |
|-----------------|
6. | 84 1.389093 |
7. | 85 1.477987 |
8. | 86 1.668846 |
9. | 87 1.885685 |
10. | 88 2.04798 |
|-----------------|
11. | 89 2.082082 |
12. | 90 2.10851 |
+-----------------+
.
. log close
name: <unnamed>
log: Z:\home\pacha\github\advanced-international-trade\first-edition\Chapt
> er-8\pindex_c.log
log type: text
closed on: 19 Jun 2024, 18:41:01
----------------------------------------------------------------------------------
.
end of do-file
```
#### pindex_t.do
```stata
clear
capture log close
log using Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\pindex_t.log,replace
use Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\truck_7990,clear
keep year model type price quan
preserve
keep if year==80
keep model type price quan
ren price price_80
ren quan quan_80
sort model
save Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\truck_80,replace
restore
sort model
merge model using Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\truck_80
keep if _merge==3
drop _merge
sort year model
egen value_80=sum(price_80*quan_80), by(year)
egen value_cp=sum(price*quan_80),by(year)
gen lasp=value_cp/value_80
egen value_c=sum(price*quan), by(year)
egen value_cq=sum(price_80*quan), by(year)
gen pasp=value_c/value_cq
gen pindex=(lasp*pasp)^0.5
collapse (mean) pindex, by(year)
list
log close
```
Output:
```stata
. clear
. capture log close
. log using Z:\home\pacha\github\advanced-international-trade\first-edition\Chapte
> r-8\pindex_t.log,replace
(note: file Z:\home\pacha\github\advanced-international-trade\first-edition\Chapte
> r-8\pindex_t.log not found)
----------------------------------------------------------------------------------
name: <unnamed>
log: Z:\home\pacha\github\advanced-international-trade\first-edition\Chapt
> er-8\pindex_t.log
log type: text
opened on: 19 Jun 2024, 18:59:29
.
. use Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\tr
> uck_7990,clear
. keep year model type price quan
.
. preserve
. keep if year==80
(110 observations deleted)
. keep model type price quan
. ren price price_80
. ren quan quan_80
. sort model
. save Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\t
> ruck_80,replace
file Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\tru
> ck_80.dta saved
. restore
.
. sort model
. merge model using Z:\home\pacha\github\advanced-international-trade\first-editio
> n\Chapter-8\truck_80
(note: you are using old merge syntax; see [R] merge for new syntax)
variable model does not uniquely identify observations in the master data
. keep if _merge==3
(38 observations deleted)
. drop _merge
.
. sort year model
. egen value_80=sum(price_80*quan_80), by(year)
. egen value_cp=sum(price*quan_80),by(year)
. gen lasp=value_cp/value_80
.
. egen value_c=sum(price*quan), by(year)
. egen value_cq=sum(price_80*quan), by(year)
. gen pasp=value_c/value_cq
(21 missing values generated)
.
. gen pindex=(lasp*pasp)^0.5
(21 missing values generated)
.
. collapse (mean) pindex, by(year)
. list
+-----------------+
| year pindex |
|-----------------|
1. | 79 .970215 |
2. | 80 1 |
3. | 81 1.278085 |
4. | 82 1.309353 |
5. | 83 1.210055 |
|-----------------|
6. | 84 1.230847 |
7. | 85 1.252268 |
8. | 86 . |
9. | 87 . |
10. | 88 . |
|-----------------|
11. | 89 . |
12. | 90 . |
+-----------------+
.
. log close
name: <unnamed>
log: Z:\home\pacha\github\advanced-international-trade\first-edition\Chapt
> er-8\pindex_t.log
log type: text
closed on: 19 Jun 2024, 18:59:31
----------------------------------------------------------------------------------
.
end of do-file
```
#### unit_value.do
```stata
clear
capture log close
log using Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\unit_value.log,replace
use Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\car_7990,clear
gen value=price*quan
egen aquan=mean(quan), by(year)
egen avalue=mean(value), by(year)
gen uvalue=avalue/aquan
collapse (mean) uvalue, by(year)
list
clear
use Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\truck_7990,clear
gen value=price*quan
egen aquan=mean(quan), by(year)
egen avalue=mean(value), by(year)
gen uvalue=avalue/aquan
collapse (mean) uvalue, by(year)
list
clear
log close
exit
```
Output:
```stata
. clear
. capture log close
. log using Z:\home\pacha\github\advanced-international-trade\first-edition\Chapte
> r-8\unit_value.log,replace
(note: file Z:\home\pacha\github\advanced-international-trade\first-edition\Chapte
> r-8\unit_value.log not found)
----------------------------------------------------------------------------------
name: <unnamed>
log: Z:\home\pacha\github\advanced-international-trade\first-edition\Chapt
> er-8\unit_value.log
log type: text
opened on: 19 Jun 2024, 19:13:08
.
. use Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\ca
> r_7990,clear
.
. gen value=price*quan
. egen aquan=mean(quan), by(year)
. egen avalue=mean(value), by(year)
. gen uvalue=avalue/aquan
. collapse (mean) uvalue, by(year)
. list
+-----------------+
| year uvalue |
|-----------------|
1. | 79 4945.603 |
2. | 80 5174.757 |
3. | 81 6210.741 |
4. | 82 6834.219 |
5. | 83 7069.203 |
|-----------------|
6. | 84 7518.311 |
7. | 85 8153.146 |
8. | 86 9391.989 |
9. | 87 10396.91 |
10. | 88 10840.6 |
|-----------------|
11. | 89 10492.76 |
12. | 90 11112.68 |
+-----------------+
. clear
.
. use Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\tr
> uck_7990,clear
. gen value=price*quan
. egen aquan=mean(quan), by(year)
. egen avalue=mean(value), by(year)
. gen uvalue=avalue/aquan
(45 missing values generated)
. collapse (mean) uvalue, by(year)
. list
+-----------------+
| year uvalue |
|-----------------|
1. | 79 4794.177 |
2. | 80 4937.291 |
3. | 81 6313.539 |
4. | 82 6426.264 |
5. | 83 6134.027 |
|-----------------|
6. | 84 6246.728 |
7. | 85 6249.927 |
8. | 86 . |
9. | 87 . |
10. | 88 . |
|-----------------|
11. | 89 . |
12. | 90 . |
+-----------------+
. clear
.
. log close
name: <unnamed>
log: Z:\home\pacha\github\advanced-international-trade\first-edition\Chapt
> er-8\unit_value.log
log type: text
closed on: 19 Jun 2024, 19:13:10
----------------------------------------------------------------------------------
. exit
end of do-file
```
### My code
#### pindex_c.do
```{r ch8_ex1a}
# Packages ----
library(archive)
library(haven)
library(dplyr)
library(tidyr)
library(broom)
library(knitr)
# Extract ----
fzip <- "first-edition/Chapter-8.zip"
dout <- gsub("\\.zip$", "", fzip)
if (!dir.exists(dout)) {
archive_extract(fzip, dir = dout)
}
# Read and transform ----
fout <- paste0(dout, "/feenstra_88.rds")
if (!file.exists(fout)) {
feenstra_88 <- list(
car_7990 = read_dta(paste0(dout, "/car_7990.dta")),
truck_7990 = read_dta(paste0(dout, "/truck_7990.dta"))
)
saveRDS(feenstra_88, fout)
} else {
feenstra_88 <- readRDS(fout)
}
car_7990 <- feenstra_88$car_7990 %>%
select(year, model, type, price, quan) %>%
arrange(year, model)
car_80 <- car_7990 %>%
filter(year == 80) %>%
select(model, type, price, quan) %>%
rename(price_80 = price, quan_80 = quan)
car_7990 <- car_7990 %>%
inner_join(car_80) %>%
group_by(year) %>%
mutate(
value_80 = sum(price_80 * quan_80),
value_cp = sum(price * quan_80)
) %>%
ungroup() %>%
mutate(lasp = value_cp / value_80)
car_7990 <- car_7990 %>%
group_by(year) %>%
mutate(
value_c = sum(price * quan),
value_cq = sum(price_80 * quan)
) %>%
ungroup() %>%
mutate(pasp = value_c / value_cq)
car_7990 %>%
mutate(pindex = sqrt(lasp * pasp)) %>%
group_by(year) %>%
summarise(pindex = mean(pindex))
```
#### pindex_t.do
```{r ch8_ex1b}
truck_7990 <- feenstra_88$truck_7990 %>%
select(year, model, type, price, quan) %>%
arrange(year, model)
truck_80 <- truck_7990 %>%
filter(year == 80) %>%
select(model, type, price, quan) %>%
rename(price_80 = price, quan_80 = quan)
truck_7990 <- truck_7990 %>%
inner_join(truck_80) %>%
group_by(year) %>%
mutate(
value_80 = sum(price_80 * quan_80),
value_cp = sum(price * quan_80)
) %>%
ungroup() %>%
mutate(lasp = value_cp / value_80)
truck_7990 <- truck_7990 %>%
group_by(year) %>%
mutate(
value_c = sum(price * quan),
value_cq = sum(price_80 * quan)
) %>%
ungroup() %>%
mutate(pasp = value_c / value_cq)
truck_7990 %>%
mutate(pindex = sqrt(lasp * pasp)) %>%
group_by(year) %>%
summarise(pindex = mean(pindex))
```
#### unit_value.do
```{r ch8_ex1c}
car_7990 <- feenstra_88$car_7990 %>%
mutate(value = price * quan) %>%
group_by(year) %>%
mutate(
aquan = mean(quan),
avalue = mean(value),
uvalue = avalue / aquan
)
truck_7990 <- feenstra_88$truck_7990 %>%
mutate(value = price * quan) %>%
group_by(year) %>%
mutate(
aquan = mean(quan),
avalue = mean(value),
uvalue = avalue / aquan
)
car_7990 %>%
group_by(year) %>%
summarise(uvalue = mean(uvalue))
truck_7990 %>%
group_by(year) %>%
summarise(uvalue = mean(uvalue))
```
## 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?
### Feenstra's code
#### car_reg.do
```stata
clear
capture log close
log using Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\car_reg.log,replace
use Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\car_7990,clear
drop if year>=86
tab year, gen(yd)
program define nlcar
version 7.0
if "`1'"=="?"{
global S_1 "a3 a4 a5 a6 a7 b2 b3 b4 b5 b6 b7 c1 c2 c3 c4 c5 c6 c7 c8"
global a3=1
global a4=1
global a5=1
global a6=1
global a7=1
global b2=.1
global b3=.1
global b4=.1
global b5=.1
global b6=.1
global b7=.1
global c1=.1
global c2=.1
global c3=.1
global c4=.1
global c5=.1
global c6=.1
global c7=.1
global c8=.1
exit
}
replace `1'=$a3*yd3+$a4*yd4+$a5*yd5+$a6*yd6+$a7*yd7/*
*/+exp($b2*yd2+$b3*yd3+$b4*yd4+$b5*yd5+$b6*yd6+$b7*yd7/*
*/+$c1*wght+$c2*wdth+$c3*hght+$c4*hp+$c5*tran+$c6*ps+$c7*ac+$c8)
end
nl car price
gen winv=1/exp(_b[b2]*yd2+_b[b3]*yd3+_b[b4]*yd4+_b[b5]*yd5+_b[b6]*yd6+_b[b7]*yd7/*
*/+_b[c1]*wght+_b[c2]*wdth+_b[c3]*hght+_b[c4]*hp+_b[c5]*tran+_b[c6]*ps+_b[c7]*ac+_b[c8])
gen nprice=price*winv
gen nyd3=yd3*winv
gen nyd4=yd4*winv
gen nyd5=yd5*winv
gen nyd6=yd6*winv
gen nyd7=yd7*winv
program define nlncar
version 7.0
if "`1'"=="?"{
global S_1 "a3 a4 a5 a6 a7 b2 b3 b4 b5 b6 b7 c1 c2 c3 c4 c5 c6 c7 c8"
global a3=1
global a4=1
global a5=1
global a6=1
global a7=1
global b2=.1
global b3=.1
global b4=.1
global b5=.1
global b6=.1
global b7=.1
global c1=.1
global c2=.1
global c3=.1
global c4=.1
global c5=.1
global c6=.1
global c7=.1
global c8=.1
exit
}
replace `1'=$a3*nyd3+$a4*nyd4+$a5*nyd5+$a6*nyd6+$a7*nyd7/*
*/+winv*exp($b2*yd2+$b3*yd3+$b4*yd4+$b5*yd5+$b6*yd6+$b7*yd7/*
*/+$c1*wght+$c2*wdth+$c3*hght+$c4*hp+$c5*tran+$c6*ps+$c7*ac+$c8)
end
nl ncar nprice
clear
program drop _all
log close
exit
```
Output:
```stata
. clear
. capture log close
. log using Z:\home\pacha\github\advanced-international-trade\first-edition\Chapte
> r-8\car_reg.log,replace
(note: file Z:\home\pacha\github\advanced-international-trade\first-edition\Chapte
> r-8\car_reg.log not found)
----------------------------------------------------------------------------------
name: <unnamed>
log: Z:\home\pacha\github\advanced-international-trade\first-edition\Chapt
> er-8\car_reg.log
log type: text
opened on: 19 Jun 2024, 19:28:58
.
. use Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\ca
> r_7990,clear
. drop if year>=86
(105 observations deleted)
.
. tab year, gen(yd)
year | Freq. Percent Cum.
------------+-----------------------------------
79 | 21 11.73 11.73
80 | 24 13.41 25.14
81 | 24 13.41 38.55
82 | 24 13.41 51.96
83 | 26 14.53 66.48
84 | 29 16.20 82.68
85 | 31 17.32 100.00
------------+-----------------------------------
Total | 179 100.00
.
. program define nlcar
1. version 7.0
2. if "`1'"=="?"{
3. global S_1 "a3 a4 a5 a6 a7 b2 b3 b4 b5 b6 b7 c1 c2 c3 c4 c5 c6 c7 c8"
4. global a3=1
5. global a4=1
6. global a5=1
7. global a6=1
8. global a7=1
9. global b2=.1
10. global b3=.1
11. global b4=.1
12. global b5=.1
13. global b6=.1
14. global b7=.1
15. global c1=.1
16. global c2=.1
17. global c3=.1
18. global c4=.1
19. global c5=.1
20. global c6=.1
21. global c7=.1
22. global c8=.1
23. exit
24. }
25. replace `1'=$a3*yd3+$a4*yd4+$a5*yd5+$a6*yd6+$a7*yd7/*
> */+exp($b2*yd2+$b3*yd3+$b4*yd4+$b5*yd5+$b6*yd6+$b7*yd7/*
> */+$c1*wght+$c2*wdth+$c3*hght+$c4*hp+$c5*tran+$c6*ps+$c7*ac+$c8)
26.
. end
.
. nl car price
(obs = 179)
Iteration 0: residual SS = 1.16e+10
...
Iteration 9: residual SS = 8.39e+07
Iteration 10: residual SS = 8.39e+07
Source | SS df MS Number of obs = 179
-------------+------------------------------ F( 19, 160) = 1158.52
Model | 1.1541e+10 19 607414473 Prob > F = 0.0000
Residual | 83888568 160 524303.55 R-squared = 0.9928
-------------+------------------------------ Adj R-squared = 0.9919
Total | 1.1625e+10 179 64942813.2 Root MSE = 724.0881
Res. dev. = 2845.293
(car)
------------------------------------------------------------------------------
price | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
a3 | -294.7452 723.3322 -0.41 0.684 -1723.255 1133.765
a4 | -304.9631 714.5517 -0.43 0.670 -1716.132 1106.206
a5 | -137.3977 700.8446 -0.20 0.845 -1521.497 1246.701
a6 | 72.87527 695.4052 0.10 0.917 -1300.482 1446.232
a7 | -103.4007 742.9475 -0.14 0.889 -1570.649 1363.848
b2 | .0099678 .0362994 0.27 0.784 -.06172 .0816555
b3 | .1522578 .1022847 1.49 0.139 -.0497444 .35426
b4 | .1899382 .0965319 1.97 0.051 -.0007027 .3805792
b5 | .1540892 .0959124 1.61 0.110 -.0353283 .3435068
b6 | .172972 .0944704 1.83 0.069 -.0135977 .3595417
b7 | .2274326 .0945034 2.41 0.017 .0407977 .4140675
c1 | -.0007315 .1021984 -0.01 0.994 -.2025632 .2011002
c2 | .3681958 .1019742 3.61 0.000 .1668067 .5695849
c3 | -.1431584 .0519385 -2.76 0.007 -.2457317 -.040585
c4 | .6070451 .0665196 9.13 0.000 .4756756 .7384147
c5 | .1315757 .0264479 4.97 0.000 .0793437 .1838078
c6 | .0515819 .0218212 2.36 0.019 .0084872 .0946766
c7 | .1635465 .0228493 7.16 0.000 .1184213 .2086717
c8 | 6.73024 .5719055 11.77 0.000 5.600783 7.859697
------------------------------------------------------------------------------
(SEs, P values, CIs, and correlations are asymptotic approximations)
.
. gen winv=1/exp(_b[b2]*yd2+_b[b3]*yd3+_b[b4]*yd4+_b[b5]*yd5+_b[b6]*yd6+_b[b7]*yd7
> /*
> */+_b[c1]*wght+_b[c2]*wdth+_b[c3]*hght+_b[c4]*hp+_b[c5]*tran+_b[c6]*ps+_b[c7]*ac
> +_b[c8])
.
. gen nprice=price*winv
. gen nyd3=yd3*winv
. gen nyd4=yd4*winv
. gen nyd5=yd5*winv
. gen nyd6=yd6*winv
. gen nyd7=yd7*winv
.
. program define nlncar
1. version 7.0
2. if "`1'"=="?"{
3. global S_1 "a3 a4 a5 a6 a7 b2 b3 b4 b5 b6 b7 c1 c2 c3 c4 c5 c
> 6 c7 c8"
4. global a3=1
5. global a4=1
6. global a5=1
7. global a6=1
8. global a7=1
9. global b2=.1
10. global b3=.1
11. global b4=.1
12. global b5=.1
13. global b6=.1
14. global b7=.1
15. global c1=.1
16. global c2=.1
17. global c3=.1
18. global c4=.1
19. global c5=.1
20. global c6=.1
21. global c7=.1
22. global c8=.1
23. exit
24. }
25. replace `1'=$a3*nyd3+$a4*nyd4+$a5*nyd5+$a6*nyd6+$a7*nyd7/*
> */+winv*exp($b2*yd2+$b3*yd3+$b4*yd4+$b5*yd5+$b6*yd6+$b7*yd7/*
> */+$c1*wght+$c2*wdth+$c3*hght+$c4*hp+$c5*tran+$c6*ps+$c7*ac+$c8)
26.
. end
.
. nl ncar nprice
(obs = 179)
Iteration 0: residual SS = 174.4452
...
Iteration 13: residual SS = 1.672068
Iteration 14: residual SS = 1.672068
Source | SS df MS Number of obs = 179
-------------+------------------------------ F( 19, 160) = 871.41
Model | 173.025768 19 9.10661939 Prob > F = 0.0000
Residual | 1.67206775 160 .010450423 R-squared = 0.9904
-------------+------------------------------ Adj R-squared = 0.9893
Total | 174.697836 179 .975965565 Root MSE = .1022273
Res. dev. = -328.5451
(ncar)
------------------------------------------------------------------------------
nprice | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
a3 | 410.4256 619.1744 0.66 0.508 -812.3829 1633.234
a4 | 378.927 650.2562 0.58 0.561 -905.265 1663.119
a5 | 770.6115 601.2054 1.28 0.202 -416.7099 1957.933
a6 | 624.3817 618.9925 1.01 0.315 -598.0676 1846.831
a7 | -122.9148 719.4492 -0.17 0.865 -1543.756 1297.927
b2 | .0089535 .0309918 0.29 0.773 -.0522522 .0701592
b3 | .0474345 .1093808 0.43 0.665 -.1685818 .2634509
b4 | .0938457 .108274 0.87 0.387 -.1199848 .3076761
b5 | .0195742 .1052628 0.19 0.853 -.1883094 .2274579
b6 | .0918745 .1019572 0.90 0.369 -.109481 .29323
b7 | .2189293 .1012639 2.16 0.032 .018943 .4189156
c1 | .0254744 .1207686 0.21 0.833 -.2130317 .2639805
c2 | .3565755 .1083292 3.29 0.001 .142636 .570515
c3 | -.0630705 .0554954 -1.14 0.257 -.1726685 .0465275
c4 | .6899452 .0852231 8.10 0.000 .521638 .8582524
c5 | .1428588 .0244762 5.84 0.000 .0945207 .1911968
c6 | .0581011 .0272835 2.13 0.035 .0042188 .1119834
c7 | .1473354 .033027 4.46 0.000 .0821103 .2125606
c8 | 6.328371 .5830815 10.85 0.000 5.176842 7.479899
------------------------------------------------------------------------------
(SEs, P values, CIs, and correlations are asymptotic approximations)
. clear
. program drop _all
. log close
name: <unnamed>
log: Z:\home\pacha\github\advanced-international-trade\first-edition\Chapt
> er-8\car_reg.log
log type: text
closed on: 19 Jun 2024, 19:29:06
----------------------------------------------------------------------------------
. exit
end of do-file
```
#### truck_reg.do
```stata
. clear
. capture log close
. log using Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\truck_reg.log,replace
(note: file Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\truck_reg.log not found)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
name: <unnamed>
log: Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\truck_reg.log
log type: text
opened on: 18 Oct 2024, 17:38:02
.
. use Z:\home\pacha\github\advanced-international-trade\first-edition\Chapter-8\truck_7990,clear
.
. drop if year>=86
(45 observations deleted)
. gen lnprice=log(price)
.
. tab year, gen(yd)
year | Freq. Percent Cum.
------------+-----------------------------------
79 | 10 13.33 13.33
80 | 10 13.33 26.67
81 | 11 14.67 41.33
82 | 11 14.67 56.00
83 | 10 13.33 69.33
84 | 11 14.67 84.00
85 | 12 16.00 100.00
------------+-----------------------------------
Total | 75 100.00
.
. program define nltruck_1
1. version 7.0
2. if "`1'"=="?"{
3. global S_1"a2 a3 a4 a5 a6 a7 b1 b2 b3 b4 b5 b6 b7 c1"
4. global a2=1
5. global a3=1
6. global a4=1
7. global a5=1
8. global a6=1
9. global a7=1
10. global b1=1
11. global b2=1
12. global b3=1
13. global b4=1
14. global b5=1
15. global b6=1
16. global b7=1
17. global c1=1
18. exit
19. }
20. replace `1'=exp($a2*yd2+$a3*yd3+$a4*yd4+$a5*yd5+$a6*yd6+$a7*yd7/*
> */+$b1*weight+$b2*wdth+$b3*hght+$b4*hp+$b5*tran+$b6*ps+$b7*four+$c1*1)
21. end
.
. nl truck_1 price