-
Notifications
You must be signed in to change notification settings - Fork 0
/
FRS HBAI - Fig 9 - public v3.sps
171 lines (140 loc) · 4.62 KB
/
FRS HBAI - Fig 9 - 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
* Encoding: UTF-8.
dataset close all.
output close all.
*** FRS HBAI - Fig 9 - public v3.sps.
*** v1 - Dec 2018.
*** v2 - Jul 2019: updated for 2017/18 data.
*** v3 - May 2020: updated for 2018/19 data.
*** Syntax creates Figure 9 for Bailey, Nick (2018) Poverty and the re-growth of private renting in the UK.
*** FOR INFO ON FILES STRUCTURES/LOCATIONS, SEE 'FRS HBAI - master - public v1.sps'.
*** SET FILE HANDLE HERE ONLY IF NEED TO RUN THIS FILE ON ITS OWN - otherwise comment out.
* file handle frs / name="K:/Data store/FRS".
* cd frs.
*** open file created by 'change' file.
get file='FRS HBAI working file.sav' .
DATASET NAME main.
dataset activate main.
*** select children only.
select if (ch=1).
execute.
*** 0. Preliminaries.
* poverty.
var labels low60ahc 'Low income poverty (AHC)'
/low60bhc 'Low income poverty (BHC)'.
value labels low60ahc low60bhc 0 'Not poor' 1 'Poor'.
* levels.
variable level tenure2 (nominal).
formats yearcode (f4.0).
* age - 1yr bands.
compute age2=age.
var labels age2 'Age'.
recode age2 (19=18) (else=copy).
value labels age2 18 '18/19'.
formats age2 (f2.0).
* complete cases only - here, this has no effect at present.
select if (not sysmis(tenure2) and not sysmis(yearcode) and not sysmis(age2)).
*** 1. Make dataset with means of tenure2 by year by region - for line chart.
dataset activate main.
weight by gs_newbu.
* sort cases.
sort cases by low60ahc region yearcode tenure2.
* aggregate to give number in each year/tenure group.
DATASET DECLARE aggr_4.
AGGREGATE
/OUTFILE='aggr_4'
/BREAK=low60ahc region yearcode tenure2
/N_ten4=N.
* aggregate onto that file number in each year/age group.
DATASET ACTIVATE aggr_4.
AGGREGATE
/OUTFILE=* MODE=ADDVARIABLES
/BREAK=low60ahc region yearcode
/N_all=SUM(N_ten4).
* make % in each tenure.
compute ten4=N_ten4/N_all.
execute.
* smoothing.
dataset activate aggr_4.
* 1.
sort cases by low60ahc region tenure2 yearcode.
execute.
if (lag(yearcode) lt yearcode) ten4_1=lag(ten4).
execute.
* 2.
sort cases by low60ahc region tenure2 (A) yearcode (D).
execute.
if (lag(yearcode) gt yearcode) ten4_2=lag(ten4).
execute.
* smoother.
compute ten4_12=mean(ten4_1, ten4_2).
compute ten4s=mean(ten4, ten4_12).
execute.
delete variables ten4_12 ten4_1 ten4_2 .
execute.
*** Figure 9: Line graph - 4 tenures by region by poverty.
dataset activate aggr_4.
* set chart template.
set ctemplate="chart_style 11pt nb.sgt".
* temp.
compute ten4s=ten4s*100.
formats ten4s(pct3.0).
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=low60ahc region yearcode ten4s tenure2
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
PAGE: begin(scale(1200px,600px))
SOURCE: s=userSource(id("graphdataset"))
DATA: yearcode=col(source(s), name("yearcode"))
DATA: ten4s=col(source(s), name("ten4s"))
DATA: tenure2=col(source(s), name("tenure2"), unit.category())
DATA: low60ahc=col(source(s), name("low60ahc"), unit.category())
DATA: region=col(source(s), name("region"), unit.category())
GUIDE: axis(dim(1), label(""))
GUIDE: axis(dim(2), label(""))
GUIDE: form.line(position(*, 20), color(color.darkgrey), shape(shape.dash))
GUIDE: form.line(position(*, 40), color(color.darkgrey), shape(shape.dash))
GUIDE: form.line(position(*, 60), color(color.darkgrey), shape(shape.dash))
GUIDE: form.line(position(*, 80), color(color.darkgrey), shape(shape.dash))
SCALE: linear(dim(1), min(1994), max(2018))
SCALE: linear(dim(2), min(0), max(80))
ELEMENT: line(position(yearcode * ten4s * region * low60ahc), color.interior(tenure2)), size(size."3px"))
PAGE: end()
END GPL.
OUTPUT EXPORT
/CONTENTS EXPORT=ALL MODELVIEWS=PRINTSETTING
/TIF IMAGEROOT='Fig9.tiff'
PERCENTSIZE=100.
OUTPUT SAVE NAME=*
OUTFILE='Figure 9.spv'
LOCK=NO.
*** write csv file for fig.
* add string var for tenure.
* add string var for tenure.
string tenurename (A20).
if (tenure2=1) tenurename='Owner occupier'.
if (tenure2=2) tenurename='Social rent'.
if (tenure2=3) tenurename='Private rent'.
if (tenure2=4) tenurename='Rent free'.
* add string var for region.
string regionname (A20).
if (region=1) regionname='London'.
if (region=2) regionname='South'.
if (region=3) regionname='Midlands'.
if (region=4) regionname='North/Wales'.
if (region=5) regionname='Scotland'.
if (region=6) regionname='Northern Ireland'.
* poverty.
rename variables (low60ahc = poverty).
string povertyname (A20).
if (poverty=0) povertyname='Not poor'.
if (poverty=1) povertyname='Poor'.
execute.
* csv - reordering vars.
SAVE TRANSLATE OUTFILE='FRS HBAI - fig 9.csv'
/TYPE=CSV
/ENCODING='UTF8'
/keep yearcode region regionname tenure2 tenurename poverty povertyname ten4s
/MAP
/REPLACE
/FIELDNAMES
/CELLS=VALUES.