Stata:
Linear Regression
Stata 3, linear regression
Hein Stigum
Presentation, data and programs at:
http://folk.uio.no/heins/
courses
Apr-15
H.S.
1
Birth weight by gestational age
SYNTHETIC
Apr-15
DATA EXAMPLE
H.S.
2
Linear regression
Birth weight
by
gestational age
Apr-15
H.S.
3
Regression idea
2500 3000 3500 4000 4500 5000
model: y  b0  b1 x  e
y = outcome
x = covariate
b1  coefficient , effectof x
e  error,residual
250
260
270
280
290
gestational age (days)
300
310
model with manycofactors: y  b0  b1 x1  b2 x2  e
x1 , x 2 = covariate
Apr-15
H.S.
4
Model, measure and assumptions
• Model
y  0  1x1  2 x2   ,   N (0, 2 )
• Association measure
1 = change in y for one unit increase in x1
• Assumptions
– Independent errors
– Linear effects
– Constant error variance
• Robustness
– influence
Apr-15
H.S.
5
Association measure
Model:
Start with:
y  β0  β1 x1  β2 x2
y1  y x1  2  y x1 1
 β0  2 β1  β2 x2
 β0  1 β1  β2 x2

Hence:
Apr-15
β1
y1  β1
H.S.
6
Purpose of regression
• Estimation
– Estimate association between outcome and
exposure adjusted for other covariates
• Prediction
– Use an estimated model to predict the
outcome given covariates in a new dataset
Apr-15
H.S.
7
Outcome distributions by exposure
Exposed
-3
0
1
Outcome
4
Exposed
-3
0
Linear regression
Unexposed
3
Quantile regression
or
cutoff,
logistic regression
8
Linear regression
or
transform,
linear regression
Unexposed
-2
-1
2
Apr-15
0
Outcome
4
Outcome
1
2
6
H.S.
8
Workflow
C2
• DAG
education
C1
sex
• Scatter- and densityplots
• Bivariate analysis
E
D
gest age
birth weight
• Regression
– Model estimation
– Test of assumptions
• Independent errors
• Linear effects
• Constant error variance
– Robustness
• Influence
Apr-15
H.S.
9
Scatter and density plots
Distribution of birth weight for
low/high gestational age
4000
6000
Scatter of birth weight by
gestational age
gest>=280 days
2000
gest<280 days
4962
0
370
240
260
280
300
Gestational age
320
340
0
Look for deviations from linearity
and outliers
Apr-15
6000
4000
2000
Birth weight (gr)
Look for shift in shape
H.S.
10
Syntax
• Estimation
– regress y x1 x2
– regress y c.age i.sex
– regress y c.age##i.sex
linear regression
continuous age, categorical sex
main+interaction
• Compare models
– estimates store m1
– estimates table m1 m2
– estimates stats m1 m2
save model
compare coefficients
compare model fit
• Post estimation
– predict res, residuals
Apr-15
predict residuals
H.S.
11
Model 1: outcome+exposure
regress bw gest
crude model
estimates store m1
store model results
Apr-15
H.S.
12
Model 2 and 3: Add covariates
regress bw gest i.educ sex
estimates table m1 m2 m3
add covariates
compare coefs
Estimate association:
m1 is biased, m2=m3
m3 more precise?
estimates stats m1 m2 m3
compare fit
Prediction:
m3 is best
Apr-15
H.S.
13
Factor (categorical) variables
• Variable
– educ = 1, 2, 3 for low, medium and high education
• Built in
– i.educ
– ib3.educ
use educ=1 as base (reference)
use educ=3 as base (reference)
• Manual “dummies”
– educ=1 as base, make dummies for 2 and 3
– generate Medium =(educ==2) if educ<.
– generate High
=(educ==3) if educ<.
Apr-15
H.S.
14
Create meaningful constant
Expected birth weight:
E(bw)  0  1  gest  2  educ2  3  educ3  4  sex
Expected birth weight at:
gest=
0, educ=1, sex=0, not meaningful

0

 1572gr

0  1  280  3426gr
gest=280, educ=1, sex=0
Margins:
margins, at(gest=
0 educ=1 sex=0) = -1572 not meaningful
margins, at(gest= 280 educ=1 sex=0) = 3426
Apr-15
H.S.
15
Results so far
coeff 95% conf. Int.
3426 (3385 , 3467)
Birth weight at ref
Gestational age
per day
17.9
Education
Low
0
Medium
71.5
High
99.1
Sex
Boy
0
Girl
-154.3
(16 , 20)
(25 , 118)
(51 , 148)
(-187 , -121)
Would normally check for interaction now!
Apr-15
H.S.
16
ASSUMPTIONS
Apr-15
H.S.
17
Test of assumptions
• Assumptions
estat hettest
p=0.9
no heteroskedasticity
Apr-15
plot residuals versus predicted y
0
-3000 -2000 -1000
predict res, residuals
predict pred, xb
scatter res pred
discuss
1000 2000
– Independent residuals:
– Linear effects:
– Constant variance:
2500
H.S.
3000
3500
Linear prediction
4000
4500
18
Violations of assumptions
• Dependent residuals
.5
1
Use mixed models or GEE
-.5
0
• Non linear effects
-1
Add square term or spline
220
240 260
gest
280
300
2
200
0
-1
-2
Use robust variance estimation
res
1
• Non-constant variance
3400
Apr-15
H.S.
3500
3600
p
3700
19
3800
Measures of influence
ROBUSTNESS
Apr-15
H.S.
20
6000
Influence idea
4000
sion
s
e
r
reg
ut
o
t
u
o
with
lier
2000
outlier
h
t
i
w
ion
regress
0
outlier
250
Apr-15
300
350
Gestational age (days)
H.S.
400
21
.2
Measures of influence
-.6
-.4
-.2
0
Remove obs 1, see change
remove obs 2, see change
1
2
10
Id
• Measure change in:
– Predicted outcome
– Deviance
– Coefficients (beta)
• Delta beta
Apr-15
H.S.
22
Leverage versus residuals2
.015
lvr2plot, mlabel(id)
.005
.01
370
529
2725
3273
2630
1723
1851
31684738
4178
64
2442
1768
2494
1164
818
4221
393
2472
3947
163
3552
567
4732
3164
4659
7
2110
2157
820
1375
1021
3037
4763
3285
843
2746
1172
4346
3715
4252
4353
490
4026
2878
342
4614
3774
2981
183
2739 1248
435
636
1269
1674
2790
2358
2634
3136
939
3414
4770
3875
2452
1516
3626
3878
888
4883
2424
1424
1286
2108
2672
3359
3677
3440
4449
2546
4310
1469
4047
2024
2295
2064
1872
1365
3137
3703
4618
4742
1308
4304
3710
4023
2738
822
4020
4788
1065
85
4683
2621
4680
3
278
212
68
2404
1704
4022
3437
3589
3664
4479
1804
4532
4254
3807
809
4341
2900
568
915
1113
610
639
658
570
3277
1729
623
177
2293
3574
391
1028
1459
573
1098
361
3970
2232
349
1669
4546
3933
771
2285
618
33
1161
4087
3689
4815
2573
97
159
1211
602
4749
4784
3422
711
2450
2928
988
3352
1313
4662
4199
3675
3275
205
3680
1058
1831
3526
2119
3852
1106
847
2881
2048
1457
4948
3336
4913
4977
1830
4133
4803
2935
3576
2759
3783
649
3107
4531
3413
334
51
4610
2886
728
1869
1916
3390
455
3004
3149
1749
2827
1307
1527
3152
1630
3705
2577
1398
4066
1158
3118
4440
2214
1845
1857
4769
3671
2469
3332
726
2292
1238
1094
2753
4808
2686
1043
280
1800
3421
3452
4959
4249
971
4050
3185
4690
2752
2595
3562
4937
211
2384
4340
3700
2053
1241
4507
3055
1392
367
1137
2142
1349
1017
3495
1788
4927
3447
1882
4473
3166
39
425
2862
3919
1157
4009
4806
1293
1245
4119
2236
4280
198
4636
804
2758
4554
4128
672
1721
2859
2685
4256
2213
1415
3786
2105
1521
2484
578
1896
2353
3996
4575
1038
4347
2017
2787
4228
3654
3721
2535
1856
1880
4590
2300
1596
283
3322
2835
2051
1890
3850
197
550
760
1936
4300
520
523
2950
4364
3427
3182
3023
1186
688
179
1402
3260
4872
215
3475
1166
4428
3466
2925
4593
2262
364
269
1932
2616
22
293
2518
2751
123
264
1731
3205
1391
3556
3886
472
2594
4632
1655
4233
1300
2537
875
1864
3944
1559
772
1455
4035
2046
3771
439
3543
3987
3119
1140
1281
2755
3028
1120
3612
3531
2158
2824
2649
999
2012
1999
4488
512
3102
561
4527
3581
4213
1634
1777
305
40
785
8
102
430
2574
823
788
3350
4881
607
1403
1615
1719
3203
3860
2294
1109
3479
2955
2547
2455
3517
617
979
1537
2776
3192
3945
1395
2150
4321
2181
1390
1587
522
4505
2025
2720
4713
944
4605
703
4902
2583
3446
4151
4663
1564
1841
2676
4583
4947
3046
1374
4207
4779
1602
3312
1648
4090
4490
3617
232
3314
2398
3115
1077
395
1053
139
3759
388
90
3874
332
399
479
684
1174
1942
3994
4559
1168
1366
1430
4102
2631
3765
313
3615
2941
4621
3018
2614
3575
62
599
2512
1007
1818
1680
3652
1876
350
1221
2669
3699
4842
3662
3199
3316
3462
1016
4289
130
352
838
4795
4681
2990
4116
4409
3881
3934
2282
2770
2947
1586
3480
2103
3130
186
4361
3555
3546
268
717
1309
1681
4906
669
4985
2591
2816
2563
3288
796
4398
2740
1670
1005
376
1839
3593
1256
4967
1114
4857
3271
4961
2629
2269
3690
1122
1147
2632
572
1136
2131
2679
2840
1377
524
2884
4074
2193
3859
4393
3978
2945
4957
1720
3916
675
1389
3972
1865
2403
3885
2822
1712
3
842
2815
2903
4586
4348
1119
1485
3036
3625
3672
3797
4318
4333
1171
259
4149
4551
1673
2315
3643
4943
2029
4043
554
1047
235
3649
4589
397
1372
4366
4480
77
2946
4127
331
745
4486
4694
1235
3545
3034
4343
3180
2533
987
1699
2486
2692
2856
2967
4204
513
2113
2525
4057
4517
2034
3746
345
1962
4655
4783
4790
2007
2889
4292
4240
1184
1054
1822
2597
3809
3611
4899
2409
2399
4045
893
2795
1206
1815
3218
4144
1268
360
4399
1794
2187
2225
1074
2727
3455
1887
832
1826
3239
2745
1041
1595
346
1939
2082
831
1679
1277
3879
3551
119
323
375
1743
2539
2607
1185
1575
1790
4452
1063
3066
3339
3767
2453
528
3209
3863
2422
3946
4012
69
2164
2287
3412
4928
3341
4968
3985
3011
3420
2771
4418
496
1597
4832
4154
4492
4706
82
885
1083
1489
1700
2173
3003
3931
1646
860
3577
1386
481
2276
2624
1276
4631
2887
3979
2646
3287
466
3804
4471
3144
3614
2199
1075
3580
565
2560
2356
2507
411
4688
3674
1917
365
1253
980
2596
1451
1985
682
385
492
560
1040
1134
1304
1901
2562
2914
3116
3344
3776
4194
4817
4875
94
3780
710
2550
4903
739
868
2568
1178
1320
2263
407
708
3841
1619
4295
1533
446
288
1162
1739
2602
4539
3201
147
4391
3106
4134
4273
2804
4518
3926
3020
3758
2449
4305
3605
3530
2311
4804
1588
1198
631
3666
3610
904
4511
1170
3905
4771
590
1423
2429
3908
551
4622
3396
110
1893
2109
4294
270
584
4247
4362
4454
1214
754
2882
2850
872
2185
3001
3423
1733
1477
3506
4402
1834
2230
3590
103
3064
3726
4920
2778
4236
1310
1263
947
4137
4385
3416
834
2264
4973
4731
1693
981
3103
421
4544
2846
4405
1659
4789
1600
3120
6
1131
4981
4703
3890
3769
1064
1688
3514
729
1534
3377
4224
4644
4897
1034
1266
1902
2505
2811
2037
2485
4421
14
505
1461
2620
2391
3644
2711
4226
663
1963
4764
3567
4084
162
1357
337
3225
4566
3583
1820
548
4954
3642
4375
3080
1332
1738
3679
1565
3399
3728
3954
1771
2070
4604
2483
611
4802
3025
1715
2039
3920
1672
2688
1773
3609
225
1433
2896
1933
244
3083
1870
2590
2068
4805
105
445
1000
1096
1259
1462
1929
1996
2217
2610
2956
3044
3504
3613
4395
4456
4679
4761
3587
1018
1599
316
338
911
2986
3047
4313
1416
1202
3242
3451
4279
805
952
1888
2095
2991
3757
2166
3472
1055
1580
4756
2072
4849
2479
643
3453
428
1285
3067
2248
2066
1295
1556
3371
4887
249
2336
917
4309
408
4299
2825
4432
3161
1774
4244
2439
2780
1636
1486
2233
1724
32
45
320
588
816
972
1970
2228
2430
2659
3293
3651
3731
4569
4701
1573
2772
840
4865
4924
965
2451
3058
3388
3628
4669
3086
2099
2238
3598
3876
4600
4633
4898
753
2783
1554
2376
807
3024
4404
2526
4474
2273
4171
2732
1891
4966
210
3383
4339
136
1990
4010
4415
302
1718
1730
2363
444
4322
4576
1348
1649
4519
1296
4156
4412
2352
1314
3968
3847
2077
1860
3138
1606
4823
966
4953
88
556
1012
1033
1061
1121
1639
1753
1801
1938
2014
2171
2268
2428
2749
2888
2938
3262
3648
4059
4464
4628
392
449
1698
2096
2626
3384
4843
199
356
1009
4657
3198
3406
4890
2863
4122
4743
4775
1299
3971
1470
3397
4658
2520
4419
464
2201
2576
3709
3909
2234
4274
2347
1889
3007
3983
4001
1452
2031
1359
2076
4159
281
3627
867
2663
4316
1351
3845
4821
1797
1613
926
3163
3261
937
2908
961
1577
2932
413
1828
3151
3554
2204
4487
223
2303
3265
1425
1410
1144
1853
2506
2226
1173
3056
1294
4378
4357
2851
4801
1209
4108
1961
2557
4109
997
118
226
287
462
469
501
698
704
821
863
970
1004
1128
1560
1702
1863
2326
2387
2873
2937
3219
3230
3394
3489
3657
3697
3747
4170
4234
4501
4612
4697
4758
4848
4944
101
275
401
1118
2354
2899
3045
3213
3537
4434
4998
161
673
1436
2662
2742
3193
4307
27
606
1092
1657
2415
2718
2729
3415
4285
696
2763
3308
3404
3768
3800
236
616
2275
2929
3557
4668
4871
1230
1785
19541955
2197
2250
2999
3330
3559
4439
850
3372
322
2080
1086
1223
1237
1653
2714
3060
4592
4596
4825
508
2715
3789
4477
4584
4915
2102
3520
2538
3936
4312
775
1919
3997
1216
2245
3467
3782
224
1384
3032
3211
3367
4120
368
1404
3503
1022
1044
4930
3548
2174
4435
1770
2761
3464
3486
4181
2086
3245
697
2466
3832
2682
4500
1097
1110
2302
3343
4562
43
4336
2534
4278
2924
3145
3302
1328
1899
1481
1339
4960
3544
4744
297
1624
3619
4851
2373
2390
1543
3362
304
1817
4933
1542
702
2278
4
628
799
1426
1842
419
2475
643
1627
2267
3761
1884
2333
2189
562
4245
357
497
171
2706
4187
4303
1705
4591
3128
3802
2678
3984
1188
245
4448
1835
2124
4778
3298
4503
1805
1419
1437
109
1497
1100
4893
3378
4820
2323
1877
2349
2931
4951
841
1504
2320
4753
553
3325
3636
387
4101
1823
4113
3717
4270
301
2677
343
4306
1608
4922
923
3749
3888
89
4645
3509
1756
151
1224
4024
4642
4793
894
1045
1528
4146
1175
3445
4189
4641
866
3906
2280
4506
1458
2319
2044
4493
3698
4370
2876
2940
1139
4834
1387
962
2006
4665
4735
692
4929
1814
2837
4040
3607
1918
2312
4143
2736
4411
4630
2126
3140
2958
2613
4272
2414
3753
3838
3156
2468
1261
1685
4649
2980
1647
2456
795
3487
1124
1667
3050
766
532
2635
3982
2367
1592
4941
3582
2705
516
619
4232
4431
3456
1250
2625
3477
4970
3541
1432
3692
4869
92
2060
4286
2182
2585
1922
4921
2907
4724
4704
646
4476
1078
2229
3229
2916
1160
891
667
3141
4416
2328
2235
4246
3448
1927
4538
749
1691
3795
1176
2599
56
681
2069
2529
384
2032
3411
3734
3553
3528
640
1289
369
3345
4579
1444
1848
266
4675
3079
3939
1651
2247
1179
2992
3300
3491
4940
4075
2633
4751
4910
4467
187
946
2078
2805
4260
2762
3112
1716
2636
2297
2489
2660
3438
4494
273
4734
3951
2556
4868
3937
3241
433
1944
3065
3683
3738
557
54
389
4925
3821
3917
4896
898
3096
3328
2380
4874
3220
3828
2464
2477
1150
613
600
1761
3702
3601
1975
859
2052
2921
4931
1494
2344
3121
770
1439
1496
1690
2206
2341
3299
4078
4489
853
1450
4011
2627
4130
4142
2680
782
2699
879
2054
2918
4577
3454
509
4792
2368
592
909
2474
3830
1561
4651
4522
52
4132
1448
4423
1
647
787
1341
1812
1874
3200
3347
3714
2175
1155
1948
4530
3169
3027
477
773
3817
4557
3190
808
1056
4975
3974
2716
2009
4352
138
1500
3162
3418
4092
3793
2218
1799
2695
2970
1420
315
4978
91
1068
837
2504
2500
4027
609
2684
3071
3766
4014
4382
4384
1327
3259
4038
400
1329
2346
3111
3638
1980
3569
1829
2192
2316
4460
1236
3248
3811
1525
2800
730
4723
3391
4139
4573
2038
4319
798
2411
1367
1463
4135
1563
500
4080
3653
4580
2978
2877
4699
3459
732
2891
3017
3656
3725
3992
4097
4870
314
344
2011
1378
1796
3176
3320
206
2370
4609
1182
1610
3940
705
3816
1662
4816
3237
3943
3215
4900
2111
3861
1568
3637
4267
1413
65
2565
438
1360
1431
4230
4932
1629
3719
2324
383
3210
5
253
552
1234
2722
3791
3279
4121
4976
3634
3701
1725
2823
2960
1330
3542
1212
3457
4153
2385
3202
701
1943
3844
4491
932
3673
4258
738
817
1361
2395
2959
1323
2869
3572
321
2421
2748
685
2836
2754
3
2664
448
604
3424
3724
668
4255
854
4773
1123
4956
160
1464
2147
2386
2567
3959
4705
1318
3450
3560
4201
887
4523
660
1941
4442
2750
4850
1591
3398
4215
4629
559
583
1409
1984
2393
3686
4504
29
3093
72
3043
3781
3932
1297
2733
3061
3068
4406
2331
4096
1135
1231
3443
4186
1909
930
2036
3864
192
539
3540
3310
2628
4853
167
4548
3
3195
2611
99
468
1201
2253
2443
3188
3834
4553
4952
1913
290
1102
319
1302
2867
1769
1354
2974
1337
3098
794
4042
4495
1762
4298
4455
4964
4265
2985
873
4946
3425
1781
1192
2071
3232
3216
3033
4660
4892
2005
2329
4451
1490
46
146
1447
1993
2756
3402
3474
3956
4264
58
3132
3311
3773
1824
3518
1484
4689
4807
4974
2019
2134
473
2917
2905
3433
4597
687
426
282
1605
2191
3953
4367
810
2200
2674
1343
2231
848
1843
3077
842
243
4061
1803
2524
902
178
716
3154
2366
3524
833
117
2016
83
113
1711
2000
2465
3315
3374
3667
4218
2026
2172
3349
4533
4979
153
940
3346
3436
4885
722
950
1952
1967
3882
4345
4811
742
3496
4502
3961
1069
2221
3090
2844
4242
2008
4100
4472
1412
4079
329
3499
4712
2314
4389
1388
2445
3297
325
3040
4387
4564
869
2195
1930
1765
700
1759
4992
4237
635
800
2155
678
3088
4461
801
3585
2578
1875
642
691
1380
1594
1928
1976
2820
2819
3030
3170
3872
4174
4661
2202
2569
2600
2704
2789
11
74
585
803
1020
1468
3429
1095
2239
2897
185
2460
3694
4089
4206
1487
354
2063
21
2271
4184
924
190
2598
200
164
1414
827
1547
1987
3568
483
4626
330
482
1322
3148
2459
2274
4193
1910
3494
601
4457
4115
3174
4248
2313
3988
3375
929
166
1571
1346
1989
415
1125
4520
4485
3327
95
2640
3558
1557
1151
2317
3183
3243
3669
3803
4430
1127
2834
2619
3639
4717
107
1617
2351
3181
537
1130
2084
2132
1784
2013
2807
3707
3914
42
57
3732
757
1002
2209
1836
3837
1084
2648
949
1052
4545
4856
543
3264
3621
2501
1208
3109
3806
2330
1780
2658
4160
4013
126
518
1620
502
3792
3602
1844
3502
2553
2
2911
2707
755
4656
4762
1013
2694
3616
3884
1969
2471
4177
4707
1645
4627
291
1572
2681
1555
169
3991
4757
3819
1115
4888
418
839
1060
1159
1326
2364
2781
4086
144
1353
1652
2532
2586
35913592
475
2564
4363
1418
2023
2190
4167
4715
1371
2050
4088
2488
3127
674
1027
1340
1953
3843
3194
3449
3720
2028
2609
2447
1604
4162
1471
3385
1079
4053
4446
4768
260
3975
1254
968
1635
2340
3235
1495
1666
4535
3117
3135
4390
608
1546
4787
2448
184
1511
777
1072
1883
2397
3578
3231
1807
487
1579
3009
3073
3805
2791
1713
4334
3123
3822
328
4844
4459
3507
3871
2809
614
1925
574
759
1001
571
4062
37
181
195
220
741
912
960
1220
1846
2318
3081
3085
3323
3935
3995
4615
204
1428
3207
3727
4983
1298
2497
2843
4994
2141
3730
4445
858
1306
4686
882
4879
1717
324
4534
3618
4635
4095
1809
3536
4202
3868
1947
3049
274
3980
4155
2542
1755
4510
1369
2433
1247
3896
3928
2515
1393
2651
359
1338
3178
4854
3629
4846
76
2898
1701
4
4901
1536
35
3129
1015
3368
607
4721
3498
377
1213
402
2418
4317
9
3798
694
1499
122
208
581
752
806
1019
2098
2115
2360
2487
2584
3039
3212
3929
4002
4166
4243
4617
4839
1873
2866
525
1727
3831
4371
311
1808
2257
2987
1637
2392
3015
3513
1260
217
3221
3739
2724
4453
18
292
793
4822
48
4914
145
2381
2617
3307
1232
3321
2410
298
2420
2865
3510
1968
3820
4017
725
1837
2853
3159
1143
1401
4469
176
991
707
975
2198
731
196
605
4315
2774
2969
1567
2255
3790
2998
3008
156
1695
3236
1710
4639
2948
2246
1279
2010
491
4625
1775
84
3463
3233
124
1145
406
1207
789
256
2975
4708
3516
2641
1570
679680
683
892
1169
1189
1612
2379
2857
3087
3110
3173
3840
4098
4262
228
493
1493
1767
1971
2160
4565
380
2092
2650
3246
3960
4587
1454
4496
296
3687
4205
4714
897
2321
2703
2799
4065
1601
4114
769
2417
3186
3535
4018
1399
4508
441
852
2587
4408
4728
371
3244
857
2545
3925
976
272
719
3458
4219
881
3704
4972
1740
630
3756
442
994
2145
2480
2786
776
908
3967
129
262
1583
3126
990
1405
1590
1787
4150
4293
3678
3762
2528
463
3360
3175
4829
1709
158
168
4032
693
2812
447
2259
3519
4667
3434
1850
373
4537
4433
1714
713
495
2389
173
629
790
922
925
1103
1177
1747
2814
2855
2957
3476
3848
4085
4263
4777
1082
1352
1445
2152
2868
3053
3354
3897
3965
4104
4982
686
900
1105
2260
3889
4595
4859
1522
1593
2412
3635
3814
396
1008
1682
2129
2224
3357
3772
4499
1152
4107
443
1101
1881
2570
2654
3223
2858
55
1187
4331
4475
1626
1892
3100
3124
4664
4678
104
4716
3252
3473
934
1640
3858
4570
622
3006
1772
3
3856
811
1501
2848
2951
3358
1080
1656
919
1515
25712572
2242
1284
3042
3733
133
2622
2211
1825
1
4377
1215
2266
1508
4963
2118
625
865
1434
2810
1810
2849
2977
1957
2934
3417
3074
3801
4830
1301
2982
4
1991
4521
3532
386
152
4055
4549
168
4000
4726
1798
612
1217
3942
3880
1766
4891
1278
4396
3930
1
1658
666
335
4425
191
4619
1689
381
409
417
802
2208
2212
3059
3305
3376
3386
4800
1153
1509
1558
2001
2904
3794
3892
422
4165
4388
333
459460
527
1311
2444
3891
1584
2296
2382
3301
1251
4581
626
2372
4847
985
2457
3958
2880
2176
2813
1706
3523
594
957
1581
1920
3596
3099
2522
2808
3849
634
2702
234
1024
2298
4046
4772
4330
4794
1735
4907
2854
3131
4799
2747
3927
1117
2543
2683
4117
2286
1683
2137
864
2743
3760
1776
3292
1317
363
3319
4676
555
4214
1345
3002
6
261
1535
1510
1816
4124
4710
4568
3167
140
1
2668
170
2035
724
3113
2653
390
57
2806
1598
037
125
374
3084
3
1358
75
379
2426
3706
595
3108
519
954
2997
4239
3460
1576
4103
1641
828
86
303
336
405
709
1006
1512
1923
2332
2687
2826
2828
3257
3622
3854
4414
4422
4640
4647
4646
4752
920
936
1871
2842
3147
3485
4314
4606
4623
24
246
653
1183
1506
3718
4984
645
1026
1833
2721
2953
4327
4884
1465
1480
3134
3650
141
1239
2926
3910
665
1958
3157
3742
655
1429
3012
2169
2767
429
1894
410
2719
420
2521
3588
4368
26
2402
3903
815
2582
3895
4837
278
3923
4030
4301
19
4126
3921
4833
471
1258
3348
252
4082
73
1274
4041
4355
4271
1549
2130
659
3082
1394
824
544
2085
3214
4131
3647
2966
2657
781
2988
579
1467
137
534
2136
2490
1642
4845
3744
4727
3409
2943
4671
2920
3468
3904
983
2371
2407
4360
3405
3
2281
4759
17
2879
4741
783
2874
2073
2
3645
4325
597
2558
1116
4152
4740
1076
1319
4073
220
2207
276
3823
1898
4229
2355
3962
3204
1879
4602
4945
3410
4039
1992
2979
1514
2196
98
237
461
514
689
1242
1257
1483
2243
2261
2894
2893
3272
3313
3713
3825
4209
4513
4654
4813
131
142
219
254
889
1541
1732
1760
1867
1966
2375
2984
3013
3171
3722
3824
3851
3873
4444
120
221
756
890
1255
2139
2357
2902
2965
4019
4392
964
2482
4478
4515
4698
38
2088
2901
3294
3521
4163
986
2033
3072
3708
4684
4995
797
1972
3296
3333
4818
4
3381
4222
4275
2549
3266
4070
4466
575
633
1697
2143
476
2971
3306
4048
4685
2446
2919
3226
638
695
1741
3584
53
2270
2476
2671
1154
4196
4231
2731
3373
498
1482
1622
2062
2120
3286
715
1441
3172
4064
1526
2441
3057
3815
4767
2513
3165
3331
4268
761
4110
4797
1197
2219
549
2478
1752
1926
2656
3900
2961
4044
4185
1950
1051
1540
959
931
1132
4338
2764
310
2592
504
2603
4835
1855
2133
2167
4582
1421
2470
4547
4004
1071
2875
3304
3755
1921
835
3031
2554
3
4918
706
2021
4942
210
631
4291
81
3640
3813
1334
1273
4828
2401
4483
3403
2717
10
2860
4774
16
4016
3918
2496
4814
1422
4145
2094
2782
250
3478
93
134
231
285
351
586
615
644
814
856
945
967
1050
1141
1200
1271
1440
2002
2056
2106
2423
2579
2645
2696
2760
3143
3492
3497
3500
3533
3646
3659
3763
3788
3893
3969
3977
3999
4158
4203
4208
4212
4745
4785
4827
132
763
1660
1758
1757
2258
3076
3177
1023
1745
2661
2912
3029
3247
4056
4329
4682
127
1400
1703
1878
2138
2290
2566
2589
2906
3303
3829
4603
394
664
1381
2090
3370
927
1029
1998
3125
1408
2378
2604
2708
4141
4335
4739
154
2154
2793
3550
4344
4481
4852
4909
239
1303
1523
1633
3796
511
4257
4470
943
1275
1905
2775
3735
4093
4328
1531
247
3256
4484
2163
2408
4060
1442
3282
4561
121
465
2514
721
844
1949
1974
32893290
3564
4991
1654
2283
2299
2394
3062
3364
3481
4091
1049
1708
1997
4862
1073
2845
3428
4118
4996
1852
2511
4251
4253
2334
3139
240
767
849
2406
1057
2041
148
1382
1791
2777
3054
3091
3224
3573
193
1025
3342
955
1793
3351
41
1228
1364
1059
2797
4302
3547
4083
750
624
2481
2936
4836
3924
4051
4791
294
2361
4164
4986
4337
587
4169
251
2832
3461
4528
2047
2
4297
2831
3505
1940
1088
3693
758
3784
2345
1983
1
2159
3407
03
3529
786
2612
580
1538
4067
20
382
258
3187
195
1035
2240
4311
1578
250
3078
2027
3870
4616
989
3283
1751
533
1623
774
996
1789
3857
63
690
3095
341
503
582
676
744
855
998
1282
1479
1552
1625
1643
1754
1779
1792
1854
1897
1907
1912
1934
2087
2097
2162
2186
2432
2454
2644
2670
2821
2963
3208
3276
3392
3465
3511
3525
3623
3853
3938
3963
3966
4099
4324
4350
4426
4498
4613
4696
374
914
1229
1290
1813
1886
2004
2045
2081
2540
2741
2871
3197
3681
42874288
4611
4673
4746
348
434
436
507
535
1668
1684
1811
2301
2536
2555
2996
3393
3395
3684
4172
656
870
1502
1986
2123
2335
2841
2870
3284
3329
4308
4552
238
1014
1356
2074
2922
3716
3729
3810
4077
4176
4351
718
1734
2122
2942
3035
3317
3439
3941
3955
4261
4693
4730
4905
79
358
452
668
1868
2252
2768
3309
4648
542
1030
1446
2104
4588
1488
1611
3238
4296
886
1553
1694
3000
3021
4403
453
1530
2527
3222
3898
4563
4786
874
1010
1107
1498
2744
454
1104
1133
1280
1981
2146
2647
2655
2709
2994
736
2440
3620
4574
566
1142
2042
2203
2350
2495
3014
3217
4359
2216
4450
116
299
918
2615
3989
2057
2864
1191
2322
71
353
499
1411
3270
3682
2416
4005
4443
289
2773
1225
4798
506
2726
4736
1644
8
904905
1435
1443
4028
4400
2993
3846
677
3234
4281
851
1524
3539
4008
431
603
1163
2933
3606
764
3538
935
2153
3408
3594
4841
378
3711
1167
2517
213
2952
3189
723
953
1062
1066
1832
3051
4889
326
1344
157
1585
4054
4550
3570
2972
654
0
2491
4182
172
3101
4558
1802
3366
3469
3565
4190
28
1603
4394
306
2510
956
2769
4
207
1764
2561
569
829
4934
541
2067
2467
4652
595
105
4147
1616
1460
2734
4695
2737
3952
4029
1746
2665
4063
1472
1222
1453
1574
2030
4766
1039
1226
4722
4755
3482
3603
2289
510
4076
1148
1548
712
4284
2205
3957
2968
265
209
4781
530
1614
30
59
155
180
248
312
318
355
404
424
450
457
486
596
598
621
620
784
907
1048
1070
1190
1240
1321
1363
1492
1520
1569
1806
1838
1861
1895
1914
1931
2020
2151
2161
2178
2180
2244
23082309
2338
2343
2413
2431
2508
2581
2593
2638
2723
2779
2890
2944
3337
3566
3641
3736
3752
3808
4025
4068
4217
4269
4358
4369
4634
4637
4650
4863
4894
4917
4949
4955
4958
4980
4988
4987
149
650
1036
1111
1181
1292
1397
1474
1473
1505
1545
1618
1904
2079
2116
2156
2369
2575
2608
3268
3741
3866
3973
4482
4936
4971
5000
128
792
982
1046
1243
1316
1519
1518
1960
1988
2396
2698
2798
2839
2885
2892
3069
3184
3206
3379
3483
3630
4197
4620
4754
4989
214
896
921
928
938
951
1291
1676
1945
2170
2305
2710
2713
3269
3389
3632
3835
4003
4441
4463
4512
4861
194
255
830
1350
1696
2325
2544
3041
3400
3470
4356
4373
4585
317
423
651652
977
1355
1562
2277
3089
3442
3571
3948
47
1491
1782
3663
3740
3826
4372
96
416
531
558
903
1031
1342
2135
2179
2693
3340
3508
3527
3833
3867
3915
4666
4702
339340
372
743
2833
4413
4674
4864
25
973
1042
2374
3515
4183
4560
4824
4840
4938
175
1138
1840
2265
2531
2700
3019
3356
3501
4138
4437
4542
4638
4725
4750
4916
489
1003
1539
1638
1979
3750
4021
4290
4653
1129
2766
3142
3990
4148
4397
4447
4990
284
414
1199
2913
3907
4831
34
327
485
627
1722
2107
3913
437
1011
1203
1347
3624
4776
114
382
2089
2127
2165
4031
4238
727
1196
1607
3227
3444
1650
3484
3676
3787
66
740
1089
1246
1396
1726
3150
4223
4765
538
974
3114
4058
44
536
4711
4950
480
2215
2307
432
2498
3146
3432
1333
2548
2962
4112
4157
13
451
733
1551
2288
2765
2976
916
2058
2923
3253
3335
3912
4342
1849
1946
1973
2279
3249
3369
4555
546
913
3105
1312
819
3338
3512
4709
70
1663
2249
2503
3133
3490
4524
2530
2605
3883
4211
1951
308
641
699
4235
748
1935
2093
3894
4594
4598
7
1675
4179
4780
4796
456
2697
1385
2652
3688
4125
2712
4376
1252
1270
4015
4670
4719
115
1900
3441
4572
277
547
670
671
263
1370
1532
2895
2930
1407
4810
1067
3092
4687
362
2802
3691
8
2043
3160
3696
47
106
3
2
2973
4855
2342
992
182
230
1908
1664
2362
23
4876
526
1180
4720
2509
4033
2438
2241
995
222
1632
12
484
2327
4180
685
954
1665
4
1287
4225
895
1264
1478
993
3599
1795
4497
3104
3355
2419
1937
412
1449
1427
3862
997
1911
2400
2015
4969
1087
2
174
2493
4878
1193
778
168
1336
229
883
1205
564
2114
4381
2519
3016
4191
2437
3775
1368
4540
3665
165
3295
1267
1362
3267
1456
661
2059
4192
67
271
737
4514
3365
4332
2915
862
188
593
49
78
714
876
901
948
978
1112
1218
1550
1671
1859
1964
1978
2125
2499
2523
2757
3122
3263
3280
3363
3586
3608
3778
3877
3998
4111
4420
4429
4608
4672
4677
4866
4911
366
779
1085
1099
1249
1476
1507
2223
2792
3075
3534
3561
3660
3770
3865
4259
4427
4733
218
1744
1821
3754
3836
3855
3949
40064007
4106
4241
4691
4880
4926
2306
2989
3097
3179
4277
4349
257
2083
2227
2927
2983
3712
4037
2018
2055
2435
2730
1108
4283
189
2194
2304
3094
3579
4276
735
1244
2100
2829
3471
50
286
1093
1959
2148
2365
2462
2666
2872
2883
720
1678
3723
3743
3964
3981
4123
4809
1965
2091
2852
4438
4939
135
1582
2101
3010
3661
4877
1283
1994
2144
2492
2794
3899
4320
906
1288
2458
3658
4700
15
1737
3869
1194
1438
4049
4401
762
576
836
1032
2251
2559
751
3353
4380
4462
1858
1566
1750
2359
1513
4838
111
765
2049
4140
143
3291
3748
1915
4935
1827
2838
3827
494
1503
1631
1417
1707
2817
878
3950
4543
1748
4919
3785
4216
4601
4858
2735
2784
10901091
1406
5
2463
846
1628
2606
3993
233
150
227
3191
3228
398
941
880
3745
4468
4729
861
2788
2801
4923
309
662
97
1544
845
2785
591
2184
1728
3488
4407
267
4220
2377
3493
4541
4516
637
1272
4782
100
3063
3318
4052
2689
2237
3048
589
4912
61
1373
2436
2643
1262
3737
4386
2473
2796
2121
4599
884
2861
458
241
403
440
521
648
826
877
899
942
963
1126
1149
1331
1376
1466
1661
1995
2065
2183
2310
2461
2637
2728
3026
3155
3158
3240
3522
3839
3887
4081
4136
4198
4200
4465
4536
4692
4826
4867
4882
580
1866
2061
2112
2256
2388
3334
3387
4624
4860
825
1146
1736
1783
2502
2601
4282
4737
4895
734
746
1903
2541
2618
2623
2642
3196
3361
4323
4578
515
813
910
933
969
2588
2910
3922
4175
4526
4748
470
2128
3911
4072
4129
4326
517
958
2847
4556
1315
1847
3655
216
545
3070
3401
3777
4036
488
984
1081
2003
2040
2427
2949
3005
87
347
540
3426
3976
4034
1165
1977
2701
2939
3251
3435
3799
4886
1906
4436
2284
2551
2639
3052
3430
4812
108
2383
3038
3695
4458
201
791
871
1324
1742
202
3986
3818
295
2140
2337
2818
4999
1325
3549
12
1692
2964
3281
300
1204
1233
1819
2425
2803
307
1609
1982
2348
2149
2405
1687
1885
2022
4069
112
768
4354
4718
4071
4509
1383
2339
3600
242
467
2995
1305
3324
4908
2177
4571
4819
1786
2117
3901
279
3258
26902691
1924
1265
2552
3431
36
577
1227
1956
2909
3779
3255
4525
3604
478
2667
3380
4417
4173
563
1
2673
3670
4760
474
1763
1686
1156
4965
1778
2516
2675
4747
4227
2434
3254
4188
4379
4266
2075
780
3563
4529
862
2188
3633
4873
4567
3326
1379
1475
2210
1210
4383
2272
3153
1517
3419
4161
4250
1219
2222
3812
1621
427
1529
2291
4424
2830
335
3764
4410
1677
60
632
3902
4094
3022
3751
3274
4195
4365
1589
4993
2254
0
4962
0
Apr-15
.002
.004
.006
Normalized residual squared
H.S.
.008
23
Delta-beta for gestational age
.2
dfbeta(gest)
scatter _dfbeta_1 id
-.4
-.2
0
4962
-.6
OBS, variable specific
-.8
370
0
1000
2000
3000
id
4000
5000
If obs nr 370
is removed,
beta will
change from
17.9 to 18.6
beta(gest)= 17.9
Apr-15
H.S.
24
Removing outlier
regress bw gest i.educ sex if id!=370
est store m4
est table m3 m4, b(%8.1f)
Apr-15
H.S.
25
Removing outlier
Full model N=5000
Outlier removed N=4999
coeff 95% conf. Int.
3426 (3385 , 3467)
Birth weight at ref
Gestational age
per day
17.9
Education
Low
0
Medium
71.5
High
99.1
Sex
Boy
0
Girl
-154.3
coeff 95% conf. Int.
3433 (3391 , 3474)
Birth weight at ref
Gestational age
18.5
per day
Education
0
Low
64.2
Medium
88.6
High
Sex
0
Boy
-152.7
Girl
(16 , 20)
(25 , 118)
(51 , 148)
(-187 , -121)
One outlier affected
several estimates
Apr-15
(17 , 20)
(18 , 110)
(40 , 137)
(-185 , -120)
Final model
H.S.
26
Help
• Linear regression
– help regress
• syntax and options
– help regress postestimation
•
•
•
•
•
Apr-15
dfbeta
estat hettest
lvr2plot
predict
margins
H.S.
27
bw2
NON-LINEAR EFFECTS
Apr-15
H.S.
28
5000
6000
bw2: Non-linear effects
1000
2000
3000
4000
Handle:
add
polynomial
or
spline
240
Apr-15
260
280
Gestational age
300
H.S.
320
29
Non-linear effects: polynomial
regress bw2 c.gest##c.gest i.educ sex
2. order polynomial in gest
3500
3000
2500
Linear Prediction
4000
margins, at(gest=(250(10)310))
predicted bw2 by gest
marginsplot
plot
Predictive Margins with 95% CIs
250
Apr-15
260
270
280
290
Gestational age
H.S.
300
310
30
Non-linear effects: spline
• Qubic spline
mkspline g=gest, cubic nknots(4)
regress bw2 g1 g2 g3 i.educ sex
make spline with 4 knots
regression with spline
• Plot
Apr-15
3000
2500
• Linear spline
mkspline g1 280 g2=gest
regress bw2 g1 g2 i.educ sex
3500
4000
5-year integer values of gest
Predictive Margins with 95% CIs
predicted bw by gest
Linear Prediction
gen igest=5*round(gest/5)
margins, over(igest)
marginsplot
250
260
270
280
igest
290
300
310
make linear spline with knot at 280
regression with spline
H.S.
31
bw3
INTERACTION
Apr-15
H.S.
32
Interaction definitions
• Interaction: combined effect of two variables
• Scale
– Linear models
additive
• y=b0+b1x1+b2x2
both x1 and x2 = b1+b2
– Logistic, Poisson, Cox
multiplicative
• Interaction
– deviation from additivity (multiplicativity)

– effect of x1 depends on x2
Apr-15
H.S.
33
bw3: Interaction (only linear effects)
• Add interaction terms
regress bw3 c.gest##i.sex i.educ
gest-sex interaction
• Show results
margins, dydx(gest) at(sex=0)
margins, dydx(gest) at(sex=1)
Apr-15
effect of gest for boys
effect of gest for girls
H.S.
34
Summing up 1
• Build model
–
–
–
–
regress bw gest
est store m1
regress bw gest i.educ sex
est store m2
crude model
store
full model
– est table m1 m2
compare coefficients
• Interaction
– regress bw3 c.gest##i.sex i.educ
– margins, dydx(gest) at(sex=0)
test interaction
gest for boys
• Assumptions
– predict res, residuals
– predict pred, xb
– scatter res pred
Apr-15
residuals
predicted
plot
H.S.
35
Summing up 2
• Non-linearity (linear spline)
– mkspline g1 280 g2=gest
– regress bw2 g1 g2 i.educ sex
spline with knot at 280
regression with spline
• Robustness
– dfbeta(gest)
– scatter _dfbeta_1 id
Apr-15
delta-beta
plot versus id
H.S.
36