-
Notifications
You must be signed in to change notification settings - Fork 0
/
FRS HBAI - tables - public v3.sps
1430 lines (1271 loc) · 39.1 KB
/
FRS HBAI - tables - public v3.sps
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
* Encoding: UTF-8.
dataset close all.
output close all.
*** FRS HBAI - tables - public v3.sps.
*** v1 - Dec 2018.
*** v2 - Jul 2019: updated for 2017/18 data.
*** v3 - May 2020: updated for 2018/19 data.
*** Syntax creates Figure2 and 4 for Bailey, Nick (2018) Poverty and the re-growth of private renting in the UK.
*** ALSO MAKES AGGREGATE TABLES BY TENURE, YEAR, AGE, [REGION,] [POVERTY STATUS].
*** FOR INFO ON FILES STRUCTURES/LOCATIONS, SEE 'FRS HBAI - master - public v1.sps'.
*** IF RUNNING THIS SYNTAX ON ITS OWN, NEED TO SET FILE HANDLE FOR 'FRS' FOLDER HERE.
* file handle frs / name= "K:/Data store/FRS".
* cd frs.
*** Structure of syntax file.
* 0. Preliminaries.
* 1a. Tenure x age x year [whole UK].
* 1b. Tenure x age x year x poverty AHC [whole UK].
* 1c. Tenure x age x year x poverty BHC [whole UK].
* 2a. Tenure x age x year x region.
* 2b. Tenure x age x year x region x poverty AHC .
* 2c. Tenure x age x year x region x poverty BHC .
* 3. Join files for RShiny app.
*** 0. Preliminaries.
* open file created by 'change' file.
get file='FRS HBAI working file.sav' .
DATASET NAME main.
* var levels.
variable level tenure4 (nominal).
formats yearcode (f4.0).
* age - 1yr bands.
compute age2=age80.
var labels age2 'Age'.
if (age2 le 16) age2=16.
if (age2 ge 80) age2=80.
value labels age2 80 '80+'.
formats age2 (f2.0).
* freq age2 .
* complete cases only .
* descriptives tenure2 yearcode age2.
select if (not sysmis(tenure2) and not sysmis(yearcode) and not sysmis(age2)).
execute.
*** 1a. Make dataset with means of tenure4 by age2 and year with smoothing.
dataset activate main.
weight by gs_newbu.
* sort cases.
sort cases by yearcode age2 tenure4.
* aggregate to give number in each year/age/tenure group.
DATASET DECLARE aggr_1a.
AGGREGATE
/OUTFILE='aggr_1a'
/BREAK=yearcode age2 tenure4
/N_ten4=N.
* aggregate onto that file the total number in each year/age group.
DATASET ACTIVATE aggr_1a.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=yearcode age2
/N_all=SUM(N_ten4).
* make % in each tenure.
compute ten4=N_ten4/N_all.
* freq ten4 /histogram /formats notable /statistics all.
* freq N_ten4 /histogram /formats notable.
execute.
* patch for missing values (i.e. year/age/tenure combinations where no cases).
* make blank dataset with case for every year/age/tenure combination.
INPUT PROGRAM.
LOOP yearcode=1994 TO 2018.
LEAVE yearcode.
- LOOP tenure4=1 TO 4.
- LEAVE tenure4.
- LOOP age2=16 to 80.
- END CASE.
- END LOOP.
- END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM.
execute.
sort cases by yearcode age2 tenure4.
dataset name temp.
dataset activate temp.
* match prev data on to this one.
MATCH FILES file=* /file=aggr_1a
by yearcode age2 tenure4.
execute.
* where no data for ten4, set to zero i.e. assume minimal numbers before starting smoothing.
if (sysmis(ten4)) ten4=0.
execute.
* patch where N_all missing.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=yearcode age2
/N_all2=SUM(N_ten4).
execute.
* close original aggregated file and replace with new.
DATASET CLOSE aggr_1a.
dataset copy aggr_1a.
dataset close temp.
* smoothing process - creates average for four adjacent cells hor and vert; takes ave of cell and that average. .
dataset activate aggr_1a.
* 1.
sort cases by tenure4 yearcode age2.
execute.
if (lag(age2) lt age2) ten4_1=lag(ten4).
execute.
* 2.
sort cases by tenure4 yearcode (A) age2 (D).
execute.
if (lag(age2) gt age2) ten4_2=lag(ten4).
execute.
* 3.
sort cases by tenure4 age2 yearcode.
execute.
if (lag(yearcode) lt yearcode) ten4_3=lag(ten4).
execute.
* 4.
sort cases by tenure4 age2 (A) yearcode (D).
execute.
if (lag(yearcode) gt yearcode) ten4_4=lag(ten4).
execute.
* smoothing - mean of cell plus four adjacents.
compute ten4s=mean(ten4, ten4_1, ten4_2, ten4_3, ten4_4).
execute.
delete variables ten4_1 ten4_2 ten4_3 ten4_4.
execute.
* checking: within each yearcode x age2 group, check that sum of ten4 and ten42 percentages is 1 in every case.
sort cases by yearcode age2 tenure4.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=yearcode age2
/ten4_sum=SUM(ten4)
/ten4s_sum=SUM(ten4s).
descriptives ten4_sum ten4s_sum.
* make smoothed count for all cases, inc. those where no data in original.
compute N_ten4s = N_all2 * ten4s.
execute.
* check to see if sum of counts for the different tenures equals total for yearcode x age2 group - checks should be zero in every case.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=yearcode age2
/N_ten4s_sum=SUM(N_ten4s).
compute check=n_ten4s_sum - N_all2.
compute checkpct=check/n_ten4s_sum.
descriptives check checkpct.
* add UK/region identifiers.
compute region=0.
STRING regname (A20).
compute regname='UK'.
execute.
*** Figure 2: tenure by age heatmap - for checking here.
* set chart template.
set ctemplate="chart_style 11pt nb.sgt".
temp.
compute ten4s=ten4s*100.
formats ten4s (pct3.0).
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=yearcode age2 tenure4 ten4s
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
PAGE: begin(scale(1500px,800px))
SOURCE: s=userSource(id("graphdataset"))
DATA: yearcode=col(source(s), name("yearcode"), unit.category())
DATA: age2=col(source(s), name("age2"), unit.category())
DATA: tenure4=col(source(s), name("tenure4"), unit.category())
DATA: ten4s=col(source(s), name("ten4s"))
GUIDE: axis(dim(1), label(""))
GUIDE: axis(dim(2), label(""))
ELEMENT: polygon(position(yearcode*age2*tenure4), color.interior(summary.sum(ten4s)), color.exterior(color.grey),
transparency.exterior(transparency."0.7"))
PAGE: end()
END GPL.
EXECUTE.
* save result, reordering vars.
save outfile = 'temp1a.sav'
/keep region regname yearcode age2 tenure4 N_ten4s N_all2.
* close temp file.
dataset close aggr_1a.
*** 1b. Make dataset with means of tenure4 by age2 and year and poverty AHC with smoothing.
dataset activate main.
weight by gs_newbu.
* set temporary poverty measure to AHC.
compute pov=low60ahc.
var labels pov 'Poverty status'.
value labels pov 0 'Not poor' 1 'Poor'.
formats pov (f2.0).
* check listwise deletion.
descriptives pov yearcode age2 tenure4.
* select only whole cases - NB: not necessary in this case.
* select if (pov ge 0 and yearcode ge 0 and age2 ge 0 and tenure4 ge 0).
* sort cases.
sort cases by pov yearcode age2 tenure4
* aggregate to give number in each year/age/tenure group.
DATASET DECLARE aggr_1b.
AGGREGATE
/OUTFILE='aggr_1b'
/BREAK=pov yearcode age2 tenure4
/N_ten4=N.
* aggregate onto that file the total number in each year/age group.
DATASET ACTIVATE aggr_1b.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=pov yearcode age2
/N_all=SUM(N_ten4).
* make % in each tenure.
compute ten4=N_ten4/N_all.
* freq ten4 /histogram /formats notable /statistics all.
* freq N_ten4 /histogram /formats notable.
execute.
* patch for missing values (i.e. year/age/tenure combinations where no cases).
* make blank dataset with case for every year/age/tenure combination.
INPUT PROGRAM.
LOOP pov=0 TO 1.
LEAVE pov.
- LOOP yearcode=1994 TO 2018.
- LEAVE yearcode.
- LOOP tenure4=1 TO 4.
- LEAVE tenure4.
- LOOP age2=16 to 80.
- END CASE.
- END LOOP.
- END LOOP.
- END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM.
execute.
sort cases by pov yearcode age2 tenure4.
dataset name temp.
* match prev data on to this one.
MATCH FILES file=* /file=aggr_1b
by pov yearcode age2 tenure4.
execute.
* where no data for ten4, set to zero i.e. assume minimal numbers before starting smoothing.
if (sysmis(ten4)) ten4=0.
execute.
* patch where N_all missing.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=pov yearcode age2
/N_all2=SUM(N_ten4).
* close original aggregated file and replace with new.
DATASET CLOSE aggr_1b.
dataset copy aggr_1b.
dataset close temp.
* smoothing process - creates average for four adjacent cells hor and vert; takes ave of cell and that average. .
dataset activate aggr_1b.
* 1.
sort cases by pov tenure4 yearcode age2.
execute.
if (lag(age2) lt age2) ten4_1=lag(ten4).
execute.
* 2.
sort cases by pov tenure4 yearcode (A) age2 (D).
execute.
if (lag(age2) gt age2) ten4_2=lag(ten4).
execute.
* 3.
sort cases by pov tenure4 age2 yearcode.
execute.
if (lag(yearcode) lt yearcode) ten4_3=lag(ten4).
execute.
* 4.
sort cases by pov tenure4 age2 (A) yearcode (D).
execute.
if (lag(yearcode) gt yearcode) ten4_4=lag(ten4).
execute.
* smoothing - mean of cell plus four adjacents.
compute ten4s=mean(ten4, ten4_1, ten4_2, ten4_3, ten4_4).
execute.
delete variables ten4_1 ten4_2 ten4_3 ten4_4.
execute.
* checking.
sort cases by pov yearcode age2 tenure4.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=pov yearcode age2
/ten4_sum=SUM(ten4)
/ten4s_sum=SUM(ten4s).
descriptives ten4_sum ten4s_sum.
* make smoothed count for all cases, inc. those where no data in original.
compute N_ten4s = N_all2 * ten4s.
execute.
* check to see if sum of tenures equals total - it doesn't due to smoothing.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=pov yearcode age2
/N_ten4s_sum=SUM(N_ten4s).
compute check=n_ten4s_sum - N_all2.
compute checkpct=check/n_ten4s_sum.
descriptives check checkpct.
* add UK/region identifiers.
compute region=0.
STRING regname (A20).
compute regname='UK'.
execute.
*** Figure 4: Tenure by age and poverty status - adults - for checking here.
* set chart template.
set ctemplate="chart_style 11pt nb.sgt".
temp.
compute ten4s=ten4s*100.
formats ten4s(pct3.0).
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=pov yearcode age2 tenure4 ten4s
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
PAGE: begin(scale(1500px,1200px))
SOURCE: s=userSource(id("graphdataset"))
DATA: yearcode=col(source(s), name("yearcode"), unit.category())
DATA: age2=col(source(s), name("age2"), unit.category())
DATA: pov=col(source(s), name("pov"), unit.category())
DATA: tenure4=col(source(s), name("tenure4"), unit.category())
DATA: ten4s=col(source(s), name("ten4s"))
GUIDE: axis(dim(1), label(""))
GUIDE: axis(dim(2), label(""))
ELEMENT: polygon(position(yearcode*age2*tenure4*pov), color.interior(summary.sum(ten4s)), color.exterior(color.grey),
transparency.exterior(transparency."0.7"))
PAGE: end()
END GPL.
EXECUTE.
* save result, reordering vars.
save outfile = 'temp1b.sav'
/keep pov region regname yearcode age2 tenure4 N_ten4s N_all2
/rename (pov = low60ahc).
dataset close aggr_1b.
*** 1c. Make dataset with means of tenure4 by age2 and year and poverty BHC with smoothing.
dataset activate main.
weight by gs_newbu.
* set temporary poverty measure to bHC.
compute pov=low60bhc.
var labels pov 'Poverty status'.
value labels pov 0 'Not poor' 1 'Poor'.
formats pov (f2.0).
* check listwise deletion.
descriptives pov yearcode age2 tenure4.
* select only whole cases - NB: not necessary in this case.
* select if (pov ge 0 and yearcode ge 0 and age2 ge 0 and tenure4 ge 0).
* sort cases.
sort cases by pov yearcode age2 tenure4
* aggregate to give number in each year/age/tenure group.
DATASET DECLARE aggr_1c.
AGGREGATE
/OUTFILE='aggr_1c'
/BREAK=pov yearcode age2 tenure4
/N_ten4=N.
* aggregate onto that file the total number in each year/age group.
DATASET ACTIVATE aggr_1c.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=pov yearcode age2
/N_all=SUM(N_ten4).
* make % in each tenure.
compute ten4=N_ten4/N_all.
* freq ten4 /histogram /formats notable /statistics all.
* freq N_ten4 /histogram /formats notable.
execute.
* patch for missing values (i.e. year/age/tenure combinations where no cases).
* make blank dataset with case for every year/age/tenure combination.
INPUT PROGRAM.
LOOP pov=0 TO 1.
LEAVE pov.
- LOOP yearcode=1994 TO 2018.
- LEAVE yearcode.
- LOOP tenure4=1 TO 4.
- LEAVE tenure4.
- LOOP age2=16 to 80.
- END CASE.
- END LOOP.
- END LOOP.
- END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM.
execute.
sort cases by pov yearcode age2 tenure4.
dataset name temp.
* match prev data on to this one.
MATCH FILES file=* /file=aggr_1c
by pov yearcode age2 tenure4.
execute.
* where no data for ten4, set to zero i.e. assume minimal numbers before starting smoothing.
if (sysmis(ten4)) ten4=0.
execute.
* patch where N_all missing.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=pov yearcode age2
/N_all2=SUM(N_ten4).
* close original aggregated file and replace with new.
DATASET CLOSE aggr_1c.
dataset copy aggr_1c.
dataset close temp.
* smoothing process - creates average for four adjacent cells hor and vert; takes ave of cell and that average. .
dataset activate aggr_1c.
* 1.
sort cases by pov tenure4 yearcode age2.
execute.
if (lag(age2) lt age2) ten4_1=lag(ten4).
execute.
* 2.
sort cases by pov tenure4 yearcode (A) age2 (D).
execute.
if (lag(age2) gt age2) ten4_2=lag(ten4).
execute.
* 3.
sort cases by pov tenure4 age2 yearcode.
execute.
if (lag(yearcode) lt yearcode) ten4_3=lag(ten4).
execute.
* 4.
sort cases by pov tenure4 age2 (A) yearcode (D).
execute.
if (lag(yearcode) gt yearcode) ten4_4=lag(ten4).
execute.
* smoothing - mean of cell plus four adjacents.
compute ten4s=mean(ten4, ten4_1, ten4_2, ten4_3, ten4_4).
execute.
delete variables ten4_1 ten4_2 ten4_3 ten4_4.
execute.
* checking.
sort cases by pov yearcode age2 tenure4.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=pov yearcode age2
/ten4_sum=SUM(ten4)
/ten4s_sum=SUM(ten4s).
descriptives ten4_sum ten4s_sum.
* make smoothed count for all cases, inc. those where no data in original.
compute N_ten4s = N_all2 * ten4s.
execute.
* check to see if sum of tenures equals total - it doesn't due to smoothing.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=pov yearcode age2
/N_ten4s_sum=SUM(N_ten4s).
compute check=n_ten4s_sum - N_all2.
compute checkpct=check/n_ten4s_sum.
descriptives check checkpct.
* add UK/region identifiers.
compute region=0.
STRING regname (A20).
compute regname='UK'.
execute.
* Figure 4 BHC: Tenure by age and poverty status - adults.
* set chart template.
set ctemplate="chart_style 14pt nb.sgt".
*.
temp.
compute ten4s=ten4s*100.
formats ten4s(pct3.0).
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=pov yearcode age2 tenure4 ten4s
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
PAGE: begin(scale(2000px,1600px))
SOURCE: s=userSource(id("graphdataset"))
DATA: yearcode=col(source(s), name("yearcode"), unit.category())
DATA: age2=col(source(s), name("age2"), unit.category())
DATA: pov=col(source(s), name("pov"), unit.category())
DATA: tenure4=col(source(s), name("tenure4"), unit.category())
DATA: ten4s=col(source(s), name("ten4s"))
GUIDE: axis(dim(1), label(""))
GUIDE: axis(dim(2), label(""))
ELEMENT: polygon(position(yearcode*age2*tenure4*pov), color.interior(summary.sum(ten4s)), color.exterior(color.grey),
transparency.exterior(transparency."0.7"))
PAGE: end()
END GPL.
EXECUTE.
* save result, reordering vars.
save outfile = 'temp1c.sav'
/keep pov region regname yearcode age2 tenure4 N_ten4s N_all2
/rename (pov = low60bhc).
dataset close aggr_1c.
*** 2a. Make dataset for tenure4 by age2 by year and region with smoothing.
dataset activate main.
weight by gs_newbu.
* check listwise deletion.
descriptives region yearcode age2 tenure4.
* sort cases.
sort cases by region yearcode age2 tenure4.
* aggregate to give number in each year/age/tenure group.
DATASET DECLARE aggr_2a.
AGGREGATE
/OUTFILE='aggr_2a'
/BREAK=region yearcode age2 tenure4
/N_ten4=N.
* aggregate onto that file number in each year/age group.
DATASET ACTIVATE aggr_2a.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=region yearcode age2
/N_all=SUM(N_ten4).
* make % in each tenure.
compute ten4=N_ten4/N_all.
* freq ten4 /histogram /formats notable /statistics all.
* freq N_ten4 /histogram /formats notable.
execute.
* patch for missing values (i.e. region/year/age/tenure combinations where no cases).
INPUT PROGRAM.
LOOP region=1 TO 6.
LEAVE region.
- LOOP yearcode=1994 TO 2018.
- LEAVE yearcode.
- LOOP tenure4=1 TO 4.
- LEAVE tenure4.
- LOOP age2=16 to 80.
- END CASE.
- END LOOP.
- END LOOP.
- END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM.
execute.
sort cases by region yearcode age2 tenure4.
dataset name temp.
* match prev data on to this one.
MATCH FILES file=* /file=aggr_2a
by region yearcode age2 tenure4.
execute.
* set missing values to 0 for all cases region 1 to 5.
if (region le 5 and sysmis(ten4)) ten4=0.
* for region 6/NI, set missing values 0 only for years from 2002.
if (region=6 and yearcode ge 2002 and sysmis(ten4)) ten4=0.
execute.
* problem that ten4 does not sum to 1 if no date for given region/year/age.
* in these cases, borrow from adjacent ages first.
* make var to indicate sum of ten4 [some values not exactly 1 due to rounding].
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=region yearcode age2
/ten4_sum=SUM(ten4).
* make lag vars for ages either side.
* 1.
sort cases by region tenure4 yearcode age2.
execute.
if (lag(age2) lt age2) ten4_a=lag(ten4).
execute.
* 2.
sort cases by region tenure4 yearcode (A) age2 (D).
execute.
if (lag(age2) gt age2) ten4_b=lag(ten4).
execute.
if (ten4_sum lt .99) ten4=mean(ten4_a, ten4_b).
* check ten4_sum again.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=region yearcode age2
/ten4_sum2=SUM(ten4).
* freq ten4_sum ten4_sum2.
delete variables ten4_a, ten4_b, ten4_sum, ten4_sum2.
* make new var N_all2 so none missing.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=yearcode age2
/N_all2=SUM(N_ten4).
* replace dataset with new one.
DATASET CLOSE aggr_2a.
dataset copy aggr_2a.
dataset close temp.
* smoothing.
dataset activate aggr_2a.
* 1.
sort cases by region tenure4 yearcode age2.
execute.
if (lag(age2) lt age2) ten4_1=lag(ten4).
execute.
* 2.
sort cases by region tenure4 yearcode (A) age2 (D).
execute.
if (lag(age2) gt age2) ten4_2=lag(ten4).
execute.
* 3.
sort cases by region tenure4 age2 yearcode.
execute.
if (lag(yearcode) lt yearcode) ten4_3=lag(ten4).
execute.
* 4.
sort cases by region tenure4 age2 (A) yearcode (D).
execute.
if (lag(yearcode) gt yearcode) ten4_4=lag(ten4).
execute.
* smoothing - mean of cell plus four adjacents.
compute ten4s=mean(ten4, ten4_1, ten4_2, ten4_3, ten4_4).
execute.
delete variables ten4_1 ten4_2 ten4_3 ten4_4.
execute.
*** with region, for ten4s, need to set all NI cases from 2001 or earlier to sysmis.
if (region=6 and yearcode le 2001) ten4s=$sysmis.
*** temp checking.
dataset activate aggr_2a.
sort cases by region yearcode age2 tenure4.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=region yearcode age2
/ten4_sum=SUM(ten4)
/ten4s_sum=SUM(ten4s).
descriptives ten4_sum ten4s_sum.
* make smoothed count for all cases, inc. those where no data in original.
compute N_ten4s = N_all2 * ten4s.
execute.
* check to see if sum of tenures equals total which it should do now.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=region yearcode age2
/N_ten4s_sum=SUM(N_ten4s).
compute check=n_ten4s_sum - N_all2.
compute checkpct=check/n_ten4s_sum.
descriptives check checkpct.
* add area identifiers.
string regname (a20).
if (region=1) regname = "London".
if (region=2) regname = "South".
if (region=3) regname = "Midlands".
if (region=4) regname = "North/Wales".
if (region=5) regname = "Scotland".
if (region=6) regname = "Northern Ireland".
execute.
* Figure: Tenure by age and region as heatmap (c.f. Figure 6).
* set chart template.
set ctemplate="chart_style 14pt nb.sgt".
*.
temp.
compute ten4s=ten4s*100.
formats ten4s(pct3.0).
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=region yearcode age2 tenure4 ten4s
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
PAGE: begin(scale(2000px,2400px))
SOURCE: s=userSource(id("graphdataset"))
DATA: yearcode=col(source(s), name("yearcode"), unit.category())
DATA: age2=col(source(s), name("age2"), unit.category())
DATA: region=col(source(s), name("region"), unit.category())
DATA: tenure4=col(source(s), name("tenure4"), unit.category())
DATA: ten4s=col(source(s), name("ten4s"))
GUIDE: axis(dim(1), label(""))
GUIDE: axis(dim(2), label(""))
ELEMENT: polygon(position(yearcode*age2*tenure4*region), color.interior(summary.sum(ten4s)), color.exterior(color.grey),
transparency.exterior(transparency."0.7"))
PAGE: end()
END GPL.
EXECUTE.
save outfile = 'temp2a.sav'
/keep region regname yearcode age2 tenure4 N_ten4s N_all2.
dataset close aggr_2a.
*** 2b. Make dataset with means of tenure4 by age2 by year by region by poverty AHC with smoothing.
dataset activate main.
weight by gs_newbu.
* set poverty var to AHC.
compute pov=low60ahc.
* check listwise deletion.
* descriptives pov region yearcode age2 tenure4.
execute.
* sort cases.
sort cases by pov region yearcode age2 tenure4.
* aggregate to give number in each year/age/tenure group.
DATASET DECLARE aggr_2b.
AGGREGATE
/OUTFILE='aggr_2b'
/BREAK=pov region yearcode age2 tenure4
/N_ten4=N.
* aggregate onto that file number in each year/age group.
DATASET ACTIVATE aggr_2b.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=pov region yearcode age2
/N_all=SUM(N_ten4).
* make % in each tenure.
compute ten4=N_ten4/N_all.
* freq ten4 /histogram /formats notable /statistics all.
* freq N_ten4 /histogram /formats notable.
execute.
* patch for missing values (i.e. region/year/age/tenure combinations where no cases).
INPUT PROGRAM.
LOOP pov=0 TO 1.
LEAVE pov.
- LOOP region=1 TO 6.
- LEAVE region.
- LOOP yearcode=1994 TO 2018.
- LEAVE yearcode.
- LOOP tenure4=1 TO 4.
- LEAVE tenure4.
- LOOP age2=16 to 80.
- END CASE.
- END LOOP.
- END LOOP.
- END LOOP.
- END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM.
execute.
sort cases by pov region yearcode age2 tenure4.
dataset name temp.
* match prev data on to this one.
MATCH FILES file=* /file=aggr_2b
by pov region yearcode age2 tenure4.
execute.
* set missing values to 0 for all cases region 1 to 5.
if (region le 5 and sysmis(ten4)) ten4=0.
* for region 6/NI, set missing values 0 only for years from 2002.
if (region=6 and yearcode ge 2002 and sysmis(ten4)) ten4=0.
execute.
* problem that ten4 does not sum to 1 if no date for given region/year/age.
* in these cases, borrow from adjacent ages first.
* make var to indicate sum of ten4 [some values not exactly 1 due to rounding].
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=pov region yearcode age2
/ten4_sum=SUM(ten4).
* make lag vars for ages either side.
* 1.
sort cases by pov region tenure4 yearcode age2.
execute.
if (lag(age2) lt age2) ten4_a=lag(ten4).
execute.
* 2.
sort cases by pov region tenure4 yearcode (A) age2 (D).
execute.
if (lag(age2) gt age2) ten4_b=lag(ten4).
execute.
if (ten4_sum lt .99) ten4=mean(ten4_a, ten4_b).
execute.
* check ten4_sum again.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=pov region yearcode age2
/ten4_sum2=SUM(ten4).
* freq ten4_sum ten4_sum2.
delete variables ten4_a, ten4_b, ten4_sum, ten4_sum2.
* make new var N_all2 so none missing.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=yearcode age2
/N_all2=SUM(N_ten4).
* replace dataset with new one.
DATASET CLOSE aggr_2b.
dataset copy aggr_2b.
dataset close temp.
* smoothing.
dataset activate aggr_2b.
* 1.
sort cases by pov region tenure4 yearcode age2.
execute.
if (lag(age2) lt age2) ten4_1=lag(ten4).
execute.
* 2.
sort cases by pov region tenure4 yearcode (A) age2 (D).
execute.
if (lag(age2) gt age2) ten4_2=lag(ten4).
execute.
* 3.
sort cases by pov region tenure4 age2 yearcode.
execute.
if (lag(yearcode) lt yearcode) ten4_3=lag(ten4).
execute.
* 4.
sort cases by pov region tenure4 age2 (A) yearcode (D).
execute.
if (lag(yearcode) gt yearcode) ten4_4=lag(ten4).
execute.
* smoothing - mean of cell plus four adjacents.
compute ten4s=mean(ten4, ten4_1, ten4_2, ten4_3, ten4_4).
execute.
delete variables ten4_1 ten4_2 ten4_3 ten4_4.
execute.
* run smoothing a second time.
dataset activate aggr_2b.
* 1.
sort cases by pov region tenure4 yearcode age2.
execute.
if (lag(age2) lt age2) ten4_1=lag(ten4s).
execute.
* 2.
sort cases by pov region tenure4 yearcode (A) age2 (D).
execute.
if (lag(age2) gt age2) ten4_2=lag(ten4s).
execute.
* 3.
sort cases by pov region tenure4 age2 yearcode.
execute.
if (lag(yearcode) lt yearcode) ten4_3=lag(ten4s).
execute.
* 4.
sort cases by pov region tenure4 age2 (A) yearcode (D).
execute.
if (lag(yearcode) gt yearcode) ten4_4=lag(ten4s).
execute.
* smoother - ave of cell plus adjacents.
compute ten4s2=mean(ten4s, ten4_1, ten4_2, ten4_3, ten4_4).
compute ten4s=ten4s2.
execute.
delete variables ten4_1 ten4_2 ten4_3 ten4_4 ten4s2.
execute.
*** with region, for ten4s, need to set all NI cases from 2001 or earlier to sysmis.
if (region=6 and yearcode le 2001) ten4s=$sysmis.
*** checking sum of tenure shares is 1 in all cases - unsmoothed and smoothed.
dataset activate aggr_2b.
sort cases by pov region yearcode age2 tenure4.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=pov region yearcode age2
/ten4_sum=SUM(ten4)
/ten4s_sum=SUM(ten4s).
descriptives ten4_sum ten4s_sum.
* make smoothed count for all cases, inc. those where no data in original.
compute N_ten4s = N_all2 * ten4s.
execute.
* check to see if sum of tenures equals total which it should do now.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=pov region yearcode age2
/N_ten4s_sum=SUM(N_ten4s).
compute check=n_ten4s_sum - N_all2.
compute checkpct=check/n_ten4s_sum.
descriptives check checkpct.
* add area identifiers.
string regname (a20).
if (region=1) regname = "London".
if (region=2) regname = "South".
if (region=3) regname = "Midlands".
if (region=4) regname = "North/Wales".
if (region=5) regname = "Scotland".
if (region=6) regname = "Northern Ireland".
execute.
* Figure: Tenure by age and region as heatmap - not poor.
* set chart template.
set ctemplate="chart_style 14pt nb.sgt".
*.
temp.
select if (pov=0).
compute ten4s=ten4s*100.
formats ten4s(pct3.0).
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=region yearcode age2 tenure4 ten4s
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
PAGE: begin(scale(2000px,2400px))
SOURCE: s=userSource(id("graphdataset"))
DATA: yearcode=col(source(s), name("yearcode"), unit.category())
DATA: age2=col(source(s), name("age2"), unit.category())
DATA: region=col(source(s), name("region"), unit.category())
DATA: tenure4=col(source(s), name("tenure4"), unit.category())
DATA: ten4s=col(source(s), name("ten4s"))
GUIDE: axis(dim(1), label(""))
GUIDE: axis(dim(2), label(""))
ELEMENT: polygon(position(yearcode*age2*tenure4*region), color.interior(summary.sum(ten4s)), color.exterior(color.grey),
transparency.exterior(transparency."0.7"))
PAGE: end()
END GPL.
EXECUTE.
* Figure: Tenure by age and region as heatmap - poor.
* set chart template.
set ctemplate="chart_style 14pt nb.sgt".
*.
temp.
select if (pov=1).
compute ten4s=ten4s*100.
formats ten4s(pct3.0).
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=region yearcode age2 tenure4 ten4s
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
PAGE: begin(scale(2000px,2400px))
SOURCE: s=userSource(id("graphdataset"))
DATA: yearcode=col(source(s), name("yearcode"), unit.category())
DATA: age2=col(source(s), name("age2"), unit.category())
DATA: region=col(source(s), name("region"), unit.category())
DATA: tenure4=col(source(s), name("tenure4"), unit.category())
DATA: ten4s=col(source(s), name("ten4s"))
GUIDE: axis(dim(1), label(""))
GUIDE: axis(dim(2), label(""))
ELEMENT: polygon(position(yearcode*age2*tenure4*region), color.interior(summary.sum(ten4s)), color.exterior(color.grey),
transparency.exterior(transparency."0.7"))
PAGE: end()
END GPL.
EXECUTE.
save outfile = 'temp2b.sav'
/keep pov region regname yearcode age2 tenure4 N_ten4s N_all2
/rename (pov = low60ahc).
dataset close aggr_2b.
*** 2c. Make dataset with means of tenure4 by age2 by year by region by poverty BHC with smoothing.
dataset activate main.
weight by gs_newbu.
* set poverty var to BHC.
compute pov=low60ahc.
* check listwise deletion.
descriptives pov region yearcode age2 tenure4.
* sort cases.
sort cases by pov region yearcode age2 tenure4.