-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleaning_and_tables_03222020_FINAL.txt
3211 lines (2593 loc) · 103 KB
/
cleaning_and_tables_03222020_FINAL.txt
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
---------------------------------------------------------------------------------------------------
name: <unnamed>
log: XXX/jhr_output/cleaning_a
> nd_tables_03222020.txt
log type: text
opened on: 22 Mar 2021, 11:25:11
. global figdir XXX/figs_miles
. global outsheet XXX/jhr_outp
> ut
.
.
. foreach var in 5 {
2. if `to_`var'' {
3. use $datadir/initial_data
4. local yos = `var'
5. local group to_`var'
6. }
7. }
.
.
. compress
variable filedt_s was float now int
variable sum_combat was float now byte
variable min_combat_filedt_s was float now int
variable year was float now int
variable pna_end_dt was float now int
variable next_move_5 was int now byte
variable next_move_8 was int now byte
variable next_move_10 was int now byte
variable next_move_12 was int now byte
variable next_move_20 was int now byte
variable msa was float now int
variable state_fips was float now byte
variable re was float now byte
variable edgrp4 was float now byte
variable metaread_old was float now int
variable female was float now byte
variable metaread was float now int
variable statefip was float now byte
variable age_marr was float now int
variable date_first_kids was float now int
variable date_first_notmarr was float now int
variable spells_startdate was float now int
variable spells_re_enlist was float now byte
variable num_ssn3 was float now byte
variable maxyos was float now byte
variable new_terms was float now byte
variable onetermonly was float now byte
variable evermarr was float now byte
variable everdissolve was float now byte
variable everkids was float now byte
variable maxpaygr was float now byte
variable prom_early was float now byte
variable state was str5 now str2
variable msa_new was str6 now str4
(310,818,960 bytes saved)
.
.
. drop _merge
.
. *** merging in the county data on ammenities
. gen county_fips = countyfips
(464,136 missing values generated)
. destring county_fips, replace
county_fips: all characters numeric; replaced as long
(464136 missing values generated)
. merge m:1 county_fips using $datadir/county_natamen.dta
Result # of obs.
-----------------------------------------
not matched 1,049,493
from master 1,046,967 (_merge==1)
from using 2,526 (_merge==2)
matched 2,838,270 (_merge==3)
-----------------------------------------
.
. ren _merge merge_ammen
.
. drop metaread
. ren metaread_old metaread
.
. replace metaread = 8840 if state == "DC"
(2,354 real changes made)
.
. merge m:1 metaread year using $datadir/median_2br_rent_allyrs
(note: variable year was int, now float to accommodate using data's values)
Result # of obs.
-----------------------------------------
not matched 1,759,829
from master 1,755,097 (_merge==1)
from using 4,732 (_merge==2)
matched 2,132,666 (_merge==3)
-----------------------------------------
. ren _merge merge_2br
.
. drop statefip
.
. gen statefip = .
(3,892,495 missing values generated)
.
. replace statefip = 1 if state == "AL"
(43,114 real changes made)
. replace statefip = 2 if state == "AK"
(69,084 real changes made)
. replace statefip = 4 if state == "AZ"
(41,230 real changes made)
. replace statefip = 5 if state == "AR"
(369 real changes made)
. replace statefip = 6 if state == "CA"
(54,014 real changes made)
. replace statefip = 8 if state == "CO"
(118,248 real changes made)
. replace statefip = 9 if state == "CT"
(66 real changes made)
. replace statefip = 10 if state == "DE"
(11 real changes made)
. replace statefip = 12 if state == "FL"
(10,295 real changes made)
. replace statefip = 13 if state == "GA"
(425,574 real changes made)
. replace statefip = 15 if state == "HI"
(128,075 real changes made)
. replace statefip = 16 if state == "ID"
(11 real changes made)
. replace statefip = 17 if state == "IL"
(1,165 real changes made)
. replace statefip = 18 if state == "IN"
(4,270 real changes made)
. replace statefip = 19 if state == "IA"
(169 real changes made)
. replace statefip = 20 if state == "KS"
(91,804 real changes made)
. replace statefip = 21 if state == "KY"
(271,893 real changes made)
. replace statefip = 22 if state == "LA"
(62,334 real changes made)
. replace statefip = 23 if state == "ME"
(330 real changes made)
. replace statefip = 24 if state == "MD"
(53,172 real changes made)
. replace statefip = 25 if state == "MA"
(2,623 real changes made)
. replace statefip = 26 if state == "MI"
(651 real changes made)
. replace statefip = 27 if state == "MN"
(323 real changes made)
. replace statefip = 28 if state == "MS"
(364 real changes made)
. replace statefip = 29 if state == "MO"
(121,860 real changes made)
. replace statefip = 30 if state == "MT"
(15 real changes made)
. replace statefip = 31 if state == "NE"
(51 real changes made)
. replace statefip = 32 if state == "NV"
(49 real changes made)
. replace statefip = 33 if state == "NH"
(23 real changes made)
. replace statefip = 34 if state == "NJ"
(5,743 real changes made)
. replace statefip = 35 if state == "NM"
(3,656 real changes made)
. replace statefip = 36 if state == "NY"
(100,405 real changes made)
. replace statefip = 37 if state == "NC"
(281,027 real changes made)
. replace statefip = 38 if state == "ND"
(10 real changes made)
. replace statefip = 39 if state == "OH"
(541 real changes made)
. replace statefip = 40 if state == "OK"
(119,931 real changes made)
. replace statefip = 41 if state == "OR"
(261 real changes made)
. replace statefip = 42 if state == "PA"
(1,690 real changes made)
. replace statefip = 44 if state == "RI"
(37 real changes made)
. replace statefip = 45 if state == "SC"
(178,374 real changes made)
. replace statefip = 46 if state == "SD"
(62 real changes made)
. replace statefip = 47 if state == "TN"
(347 real changes made)
. replace statefip = 48 if state == "TX"
(474,249 real changes made)
. replace statefip = 49 if state == "UT"
(793 real changes made)
. replace statefip = 50 if state == "VT"
(14 real changes made)
. replace statefip = 51 if state == "VA"
(168,855 real changes made)
. replace statefip = 53 if state == "WA"
(145,885 real changes made)
. replace statefip = 54 if state == "WV"
(183 real changes made)
. replace statefip = 55 if state == "WI"
(426 real changes made)
. replace statefip = 56 if state == "WY"
(11 real changes made)
.
. *ren state_fip statefip
. merge m:1 statefip year using $datadir/median_2br_rent_state_allyrs_2
(label statefip_lbl already defined)
Result # of obs.
-----------------------------------------
not matched 910,204
from master 909,961 (_merge==1)
from using 243 (_merge==2)
matched 2,982,534 (_merge==3)
-----------------------------------------
. ren _merge merge_2br_state
.
. replace md_rrentgrsi = md_rrentgrsi_state if md_rrentgrsi == . & merge_2br_state == 3
(868,028 real changes made)
.
.
. *** merge in share employment data using msa
. drop shcon shman shgov shmil
.
. merge m:1 msa year using $datadir/BEA_msa, keepusing(shcon shman shgov shmil shsvc)
Result # of obs.
-----------------------------------------
not matched 1,593,376
from master 1,580,679 (_merge==1)
from using 12,697 (_merge==2)
matched 2,312,059 (_merge==3)
-----------------------------------------
. foreach var in shcon shman shgov shmil shsvc {
2. ren `var' `var'msa
3. }
. tab _merge
_merge | Freq. Percent Cum.
------------------------+-----------------------------------
master only (1) | 1,580,679 40.47 40.47
using only (2) | 12,697 0.33 40.80
matched (3) | 2,312,059 59.20 100.00
------------------------+-----------------------------------
Total | 3,905,435 100.00
. drop if _merge == 2
(12,697 observations deleted)
. ren _merge merge_msa2
. sort state_fips year
. merge m:1 state_fips year using $datadir/BEA_state, keepusing(shcon shman shgov shmil shs
> vc)
Result # of obs.
-----------------------------------------
not matched 944,285
from master 943,130 (_merge==1)
from using 1,155 (_merge==2)
matched 2,949,608 (_merge==3)
-----------------------------------------
. tab _merge
_merge | Freq. Percent Cum.
------------------------+-----------------------------------
master only (1) | 943,130 24.22 24.22
using only (2) | 1,155 0.03 24.25
matched (3) | 2,949,608 75.75 100.00
------------------------+-----------------------------------
Total | 3,893,893 100.00
.
. foreach var in shcon shman shgov shmil shsvc {
2. ren `var' `var'state
3. }
. drop if _merge == 2
(1,155 observations deleted)
. ren _merge merge_state_year2
.
. foreach var in shcon shman shgov shmil shsvc {
2. gen `var' = `var'msa if merge_msa2 == 3
3. replace `var' = `var'state if merge_state_year2 == 3 & (merge_msa2 ~= 3 | msa == . | `
> var'msa == .)
4. }
(1,580,693 missing values generated)
(657,953 real changes made)
(1,580,752 missing values generated)
(657,796 real changes made)
(1,580,679 missing values generated)
(658,000 real changes made)
(1,580,679 missing values generated)
(658,000 real changes made)
(1,580,679 missing values generated)
(658,000 real changes made)
.
. *** creating the first arloc for someone - for clustering
. sort id training filedt_s
. bys id training: gen first = _n
. replace first = 0 if first ~= 1
(3,142,410 real changes made)
.
. egen arlocnum = group(arloc)
(7,501 missing values generated)
. gen tempx = arlocnum if first == 1 & training == 0
(3,514,368 missing values generated)
. bys id: egen first_arlocnum = max(tempx)
(7,501 missing values generated)
. drop tempx
.
. **** first_term variable
. sort id filedt_s
. by id: gen numterm = _n
. gen tempterm6 = real(terms) if numterm == 1
(3,517,020 missing values generated)
.
. bys id: egen term_first = max(tempterm6)
(32,333 missing values generated)
.
. drop tempterm6
.
. gen tempterm6 = terms == "6" & numterm == 1
.
. bys id: egen term6 = max(tempterm6)
.
. forvalues x=3/4 {
2. gen tempterm`x' = terms == "`x'" & numterm == 1
3.
. bys id: egen term`x' = max(tempterm`x')
4. }
. forvalues x=5/5 {
2. gen tempterm`x' = terms == "`x'" & numterm == 1
3.
. bys id: egen terms`x' = max(tempterm`x')
4. }
.
. ****** location variables
.
. *** creating weighted average epops
.
. ** time under an epop if not in training
. gen epoptime = filedt_s[_n+1] - filedt_s if training == 0 & id == id[_n+1] & training[_n+
> 1] == 0
(1,956,313 missing values generated)
. gen epop_x_time = epop * epoptime if training == 0
(2,429,324 missing values generated)
. sort id filedt_s
. by id: gen sumtime = sum(epoptime) if epop ~= .
(922,679 missing values generated)
.
. sort id filedt_s
. by id: gen sum_epop_x_time = sum(epop_x_time)
. gen avg_epop = sum_epop_x_time/sumtime
(1,788,656 missing values generated)
. replace avg_epop = . if filedt_s > td(31dec2010)
(11,888 real changes made, 11,888 to missing)
. replace avg_epop = . if sum_epop_x_time == 0
(0 real changes made)
.
. *** creating weighted average cell shares using the same method as epop
.
. sort id training filedt_s
.
. gen celltime = filedt_s[_n+1] - filedt_s if training == 0 & id == id[_n+1] & training[_n+
> 1] == 0
(1,667,995 missing values generated)
. gen cell_x_time = cellsharei * celltime if training == 0
(2,264,592 missing values generated)
. sort id filedt_s
. by id: gen sumtime2 = sum(celltime) if cellsharei ~= .
(931,079 missing values generated)
.
. sort id filedt_s
. by id: gen sum_cell_x_time = sum(cell_x_time)
. gen avg_cellshare = sum_cell_x_time/sumtime2
(1,741,560 missing values generated)
. replace avg_cellshare = . if sum_cell_x_time == 0
(0 real changes made)
.
. *** creating weighted average cell poi using the same method as epop
.
. drop celltime cell_x_time sumtime2 sum_cell_x_time
. sort id training filedt_s
.
. gen celltime = filedt_s[_n+1] - filedt_s if training == 0 & id == id[_n+1] & training[_n+
> 1] == 0
(1,667,995 missing values generated)
. gen cell_x_time = cellpopi * celltime if training == 0 & merge_marriage_market_msa == 3
(2,678,151 missing values generated)
. sort id filedt_s
. by id: gen sumtime2 = sum(celltime) if cellpopi ~= .
(931,079 missing values generated)
.
. sort id filedt_s
. by id: gen sum_cell_x_time = sum(cell_x_time)
. gen avg_cellpop = sum_cell_x_time/sumtime2
(1,741,560 missing values generated)
. replace avg_cellpop = . if sum_cell_x_time == 0
(471,750 real changes made, 471,750 to missing)
.
. gen not_in_msa = merge_marriage_market_msa ~= 3 & training == 0
. bys id: egen ever_not_in_msa = max(not_in_msa)
.
. replace avg_cellpop = . if ever_not_in_msa == 1
(897,006 real changes made, 897,006 to missing)
.
. *** creating weighted average 2br rent price
.
. drop celltime cell_x_time sumtime2 sum_cell_x_time
. sort id training filedt_s
.
. gen celltime = filedt_s[_n+1] - filedt_s if training == 0 & id == id[_n+1] & training[_n+
> 1] == 0
(1,667,995 missing values generated)
. gen cell_x_time = md_rrentgrsi * celltime if training == 0 & md_rrentgrsi ~= .
(2,249,167 missing values generated)
. sort id filedt_s
. by id: gen sumtime2 = sum(celltime) if md_rrentgrsi ~= .
(887,535 missing values generated)
.
. sort id filedt_s
. by id: gen sum_cell_x_time = sum(cell_x_time)
. gen avg_cell2br = sum_cell_x_time/sumtime2
(1,721,248 missing values generated)
. replace avg_cell2br = . if sum_cell_x_time == 0
(0 real changes made)
.
. gen not_in_2br = md_rrentgrsi == . & training == 0
. bys id: egen ever_not_in_2br = max(not_in_2br)
.
. replace avg_cell2br = . if ever_not_in_2br == 1
(894,004 real changes made, 894,004 to missing)
.
. *** creating weighted average ammenities
.
. drop celltime cell_x_time sumtime2 sum_cell_x_time
. sort id training filedt_s
.
. gen celltime = filedt_s[_n+1] - filedt_s if training == 0 & id == id[_n+1] & training[_n+
> 1] == 0
(1,667,995 missing values generated)
. gen cell_x_time = amenityscale * celltime if training == 0 & amenityscale ~= .
(2,371,684 missing values generated)
. sort id filedt_s
. by id: gen sumtime2 = sum(celltime) if amenityscale ~= .
(1,051,942 missing values generated)
.
. sort id filedt_s
. by id: gen sum_cell_x_time = sum(cell_x_time)
. gen avg_cell_amm = sum_cell_x_time/sumtime2
(1,888,119 missing values generated)
. replace avg_cell_amm = . if sum_cell_x_time == 0
(4 real changes made, 4 to missing)
.
. gen not_in_amm = amenityscale == . & training == 0
. bys id: egen ever_not_in_amm = max(not_in_amm)
.
. replace avg_cell_amm = . if ever_not_in_amm == 1
(981,396 real changes made, 981,396 to missing)
.
. *** shcon shman shgov shmil shsvc
. foreach var in shcon shman shgov shmil shsvc {
2. drop celltime cell_x_time sumtime2 sum_cell_x_time
3. sort id training filedt_s
4.
. gen celltime = filedt_s[_n+1] - filedt_s if training == 0 & id == id[_n+1] & training[_n+
> 1] == 0
5. gen cell_x_time = `var' * celltime if training == 0 & `var' ~= .
6. sort id filedt_s
7. by id: gen sumtime2 = sum(celltime) if `var' ~= .
8.
. sort id filedt_s
9. by id: gen sum_cell_x_time = sum(cell_x_time)
10. gen avg_`var' = sum_cell_x_time/sumtime2
11. replace avg_`var' = . if sum_cell_x_time == 0
12.
. gen not_in_`var' = `var' == . & training == 0
13. bys id: egen ever_not_in_`var' = max(not_in_`var')
14. replace avg_`var' = . if filedt_s > td(31dec2010)
15.
. replace avg_`var' = . if ever_not_in_`var' == 1
16. }
(1,667,995 missing values generated)
(2,253,592 missing values generated)
(922,740 missing values generated)
(1,751,705 missing values generated)
(0 real changes made)
(11,911 real changes made, 11,911 to missing)
(970,066 real changes made, 970,066 to missing)
(1,667,995 missing values generated)
(2,253,753 missing values generated)
(922,956 missing values generated)
(1,751,938 missing values generated)
(0 real changes made)
(11,908 real changes made, 11,908 to missing)
(970,137 real changes made, 970,137 to missing)
(1,667,995 missing values generated)
(2,253,557 missing values generated)
(922,679 missing values generated)
(1,751,659 missing values generated)
(0 real changes made)
(11,912 real changes made, 11,912 to missing)
(969,945 real changes made, 969,945 to missing)
(1,667,995 missing values generated)
(2,253,557 missing values generated)
(922,679 missing values generated)
(1,751,659 missing values generated)
(0 real changes made)
(11,912 real changes made, 11,912 to missing)
(969,945 real changes made, 969,945 to missing)
(1,667,995 missing values generated)
(2,253,557 missing values generated)
(922,679 missing values generated)
(1,751,659 missing values generated)
(0 real changes made)
(11,912 real changes made, 11,912 to missing)
(969,945 real changes made, 969,945 to missing)
.
.
.
. *** going to create worse move if moving to a location with more than 1 standard deviation from t
> he previous.
.
. ** first need to create standard deviation of all possible locations
.
. foreach var in epop amenityrank md_rrentgrsi cellsharei shcon shman shgov shmil shsvc {
2. egen tempz2_`var' = std(`var')
3. }
(922,679 missing values generated)
(1,051,942 missing values generated)
(887,535 missing values generated)
(931,079 missing values generated)
(922,740 missing values generated)
(922,956 missing values generated)
(922,679 missing values generated)
(922,679 missing values generated)
(922,679 missing values generated)
.
. *** moving to a worse location in terms of cell size
. sort id training filedt_s
. gen worse_location = tempz2_cellsharei < (tempz2_cellsharei[_n-1]-1) if training == 0 &
> training[_n-1] == 0 & id == id[_n-1] & abroad ~= 1 & cellsharei[_n-1] ~= . & cellsharei ~= . & mo
> ve_not == 1
(3,751,778 missing values generated)
. gen better_location = (tempz2_cellsharei[_n-1]+1) < tempz2_cellsharei if training == 0 &
> training[_n-1] == 0 & id == id[_n-1] & abroad ~= 1 & cellsharei ~= . & cellsharei[_n-1] ~= . & m
> ove_not == 1
(3,751,778 missing values generated)
.
. gen worse_epop = tempz2_epop < (tempz2_epop[_n-1]-1) if training == 0 & training[_n-1] ==
> 0 & id == id[_n-1] & abroad ~= 1 & epop[_n-1] ~= . & epop ~= . & move_not == 1
(3,752,945 missing values generated)
. gen better_epop = (tempz2_epop[_n-1]+1) < (tempz2_epop) if training == 0 & training[_n-1
> ] == 0 & id == id[_n-1] & abroad ~= 1 & epop[_n-1] ~= . & epop ~= . & move_not == 1
(3,752,945 missing values generated)
.
.
. gen worse_amm = tempz2_amenityrank < (tempz2_amenityrank[_n-1]-1) if training == 0 & tra
> ining[_n-1] == 0 & id == id[_n-1] & abroad ~= 1 & amenityrank[_n-1] ~= . & amenityrank ~= . & mov
> e_not == 1
(3,783,244 missing values generated)
. gen better_amm = (tempz2_amenityrank[_n-1]+1) < (tempz2_amenityrank) if training == 0 & t
> raining[_n-1] == 0 & id == id[_n-1] & abroad ~= 1 & amenityrank[_n-1] ~= . & amenityrank ~= . & m
> ove_not == 1
(3,783,244 missing values generated)
.
. foreach var in shcon shman shgov shmil shsvc {
2. gen worse_`var' = tempz2_`var' < (tempz2_`var'[_n-1]-1) if training == 0 & training[_
> n-1] == 0 & id == id[_n-1] & abroad ~= 1 & `var'[_n-1] ~= . & `var' ~= . & move_not == 1
3. gen better_`var' = (tempz2_`var'[_n-1]+1) < (tempz2_`var') if training == 0 & training
> [_n-1] == 0 & id == id[_n-1] & abroad ~= 1 & `var'[_n-1] ~= . & `var' ~= . & move_not == 1
4. }
(3,752,961 missing values generated)
(3,752,961 missing values generated)
(3,753,005 missing values generated)
(3,753,005 missing values generated)
(3,752,945 missing values generated)
(3,752,945 missing values generated)
(3,752,945 missing values generated)
(3,752,945 missing values generated)
(3,752,945 missing values generated)
(3,752,945 missing values generated)
.
. gen more_exp_rent = tempz2_md_rrentgrsi > (tempz2_md_rrentgrsi[_n-1]+1) if move_not == 1
> & training == 0 & training[_n-1] == 0 & id == id[_n-1] & abroad ~= 1 & md_rrentgrsi[_n-1] ~= . &
> md_rrentgrsi ~= .
(3,750,151 missing values generated)
. gen less_exp_rent = (tempz2_md_rrentgrsi[_n-1]+1) > (tempz2_md_rrentgrsi) if move_not ==
> 1 & training == 0 & training[_n-1] == 0 & id == id[_n-1] & abroad ~= 1 & md_rrentgrsi[_n-1] ~= .
> & md_rrentgrsi ~= .
(3,750,151 missing values generated)
.
. foreach var in tempz2_cellsharei tempz2_epop tempz2_amenityrank tempz2_md_rrentgrsi tempz2_shcon
> tempz2_shman tempz2_shgov tempz2_shmil tempz2_shsvc {
2. gen ch_`var' = `var' - `var'[_n-1] if training == 0 & training[_n-1] == 0 & id == id[_
> n-1] & abroad ~= 1 & `var'[_n-1] ~= . & `var' ~= . & move_not == 1
3. }
(3,751,778 missing values generated)
(3,752,945 missing values generated)
(3,783,244 missing values generated)
(3,750,151 missing values generated)
(3,752,961 missing values generated)
(3,753,005 missing values generated)
(3,752,945 missing values generated)
(3,752,945 missing values generated)
(3,752,945 missing values generated)
.
.
. *** creating variable for initial rank
. bys id: egen mind = min(filedt_s)
(7,501 missing values generated)
. gen temprank = real(substr(grade, 3, 1))
(7,501 missing values generated)
. gen initial_rank_temp = temprank if filedt_s == mind
(3,514,368 missing values generated)
. bys id: egen initial_rank = max(initial_rank_temp)
(7,501 missing values generated)
.
.
. *** variable for large posts
. bys id arloc year: gen num_id_arloc_yr = _n
. replace num_id_arloc_yr = . if num_id_arloc_yr ~= 1
(811,491 real changes made, 811,491 to missing)
. bys arloc year: egen tot_arloc_year = total(num_id_arloc_yr)
. bys arloc year: gen num_arloc_yr = _n
. summ tot_arloc_year if num_arloc_yr == 1, de
tot_arloc_year
-------------------------------------------------------------
Percentiles Smallest
1% 1 1
5% 1 1
10% 1 1 Obs 11,164
25% 2 1 Sum of Wgt. 11,164
50% 11 Mean 275.9985
Largest Std. Dev. 1155.77
75% 83 16656
90% 386 18293 Variance 1335803
95% 1099 19432 Skewness 8.016278
99% 5675 20213 Kurtosis 84.09162
.
. gen large_post = tot_arloc_year >= r(p90)
.
. sort id training filedt_s
. gen large_to_small = large_post == 0 & move_not == 1 & training == 0 & large_post[_n-1] =
> = 1 & id == id[_n-1]
.
.
. *** creating variable for initial year
. gen initial_year = year(mind)
(7,501 missing values generated)
.
. *** are people in divisions and bcts?
. gen bct = div == 1 | bdereg == 1
.
. *** married when enter
. gen temp3 = married == 1 & firstobs == 1
. bys id: egen m_ent = max(temp3)
. drop temp3
.
. *** kids when enter
. gen temp3 = kids == 1 & firstobs == 1
. bys id: egen kids_ent = max(temp3)
. drop temp3
.
. *** married with less than a year in the Army
.
. gen less_yr = (filedt_s - startdate <= 365) & filedt_s > startdate
. gen temp5 = less_yr == 1 & marst == "M" & m_ent == 0
. bys id: egen mar_lyr = max(temp5)
. drop temp5
.
. *** age when enter
. gen temp3 = age if firstobs == 1
(3,529,368 missing values generated)
. bys id: egen age_when_enter = max(temp3)
(162,191 missing values generated)
. drop temp3
.
. ren _merge merge_old1
.
. ** figuring out age when first get married - merging in data from age_marr.do. also creates vari
> able for first time not married and first time with kids.
.
. /*age_marr is a filedt_s*/
. gen tempage = age_marr - birthmo
(819,159 missing values generated)
. gen date_marr = age_marr
(816,956 missing values generated)
. gen tempage2 = tempage/365.25
(819,159 missing values generated)
. replace tempage2 = . if tempage2 < 17 | tempage2 > 55
(400 real changes made, 400 to missing)
. drop age_marr tempage
. ren tempage2 age_marr
.
. ** timing between marriage and moves
. gen marr_filedt_s = date_marr - filedt_s if move_not == 1
(3,575,660 missing values generated)
. gen marr2 = abs(marr_filedt_s)
(3,575,660 missing values generated)
. bys id: egen marr3 = min(abs(marr_filedt_s))
(1,434,490 missing values generated)
. gen marr4 = marr_filedt_s if marr2 == marr3
(3,667,290 missing values generated)
. by id: egen marr5 = min(marr4)
(1,434,490 missing values generated)
. by id: gen marr_num = _n
. * histogram marr5 if marr_num == 1, title("Time Between Marriage and Move") frac xtitle("Ma
> rriage Date - Move Date")
. * graph export $figdir/married_move_`gr'.ps, replace
. * histogram marr5 if marr_num == 1 & female == 0, title("Time Since Marriage and Move -- ME
> N") frac
. * graph export $figdir/married_move_`gr'_m.ps, replace
. * histogram marr5 if marr_num == 1 & female == 1, title("Time Since Marriage and Move -- WO
> MEN") frac
. * graph export $figdir/married_move_`gr'_f.ps, replace
. drop marr_filedt_s marr2 marr3 marr4 marr_num
. ren marr5 days_to_move
. gen months_to_move = floor((days_to_move/30))
(1,434,490 missing values generated)
.
.
. gen shot_gun = abs(months_to_move) <= 3
. replace shot_gun = . if months_to_move == .
(1,434,490 real changes made, 1,434,490 to missing)
.
. gen m_to_m_l6 = abs(months_to_move) <= 6
. replace m_to_m_l6 = . if m_ent == 1 | evermarr == 0 | months_to_move == .
(2,561,312 real changes made, 2,561,312 to missing)
.
. gen m_to_m_g6 = abs(months_to_move) > 6
. replace m_to_m_g6 = . if m_ent == 1 | evermarr == 0 | months_to_move == .
(2,561,312 real changes made, 2,561,312 to missing)
.
. *** people who were ever abroad
. bys id: egen everabroad = max(abroad)
(7,501 missing values generated)
.
.
. *** first move
. gen date_move = filedt_s if move_not == 1
(3,493,108 missing values generated)
. bys id: egen min_date_move = min(date_move)
(803,906 missing values generated)
.
. *** same as above, but conditioning on those who were not married 6 months before a move and did
> not move again within 24 months. - just for FIRST moves
.
. *** creating a histogram which shows when people's first moves are.
.
. gen time_since_start_30 = floor((min_date_move - startdate)/30)
(803,906 missing values generated)
. *histogram time_since_start_30 if filedt_s == min_date_move
.
. *graph export $figdir/time_since_start_30.pdf, replace
.
. preserve
. keep time_since_start_30 filedt_s min_date_move term3
. save $datadir/app_fig_1, replace
file XXX/dta/app_fig_1.dta saved
. restore
.
. /*
> *** Data for figure is in jhr_app_fig_1.do
> ** Appendix C Figure 1
>
> histogram time_since_start_30 if filedt_s == min_date_move & term3 == 1
>
> graph export $figdir/time_since_start_30_term3.pdf, replace
> tab time_since_start_30 if filedt_s == min_date_move & term3 == 1
> */
.
. ***** creating yearly variables for new tables eight