Code

pavelluengassierra

Untitled

12/3/20, 4:02 PM

1 *==========

2

3 /* Sources

4 (a) Forecast and errors:

5 NOV. 3, 2020

6 Biden’s Favored In Our Final Presidential Forecast, But It’s A

Fine Line Between A Landslide And A Nail-Biter

7 By Nate Silver

8 https://fivethirtyeight.com/features/final-2020-presidential-electio

n-forecast/

9 */

10

11 clear

12

13 set obs 17

14

15 gen state = ""

16

17 replace state = "New Hampshire" if _n==1

18 replace state = "Minnesota" if _n==2

19 replace state = "Wisconsin" if _n==3

20 replace state = "Michigan" if _n==4

21 replace state = "Nevada" if _n==5

22 replace state = "Pennsylvania" if _n==6

23 replace state = "Arizona" if _n==7

24 replace state = "Florida" if _n==8

25 replace state = "North Carolina" if _n==9

26 replace state = "Georgia" if _n==10

27 replace state = "Ohio" if _n==11

28 replace state = "Iowa" if _n==12

29 replace state = "Texas" if _n==13

30 replace state = "Montana" if _n==14

31 replace state = "South Carolina" if _n==15

32 replace state = "Alaska" if _n==16

33 replace state = "Missouri" if _n==17

34

35 * Forecast based on polls (538) vs Preliminary results

36 gen f538_for = .

Page 1 of 6


Untitled

12/3/20, 4:02 PM

36 gen f538_for = .

37 gen f538_Berr = .

38 gen f538_Rerr = .

39

40 ** "New Hampshire"

41 replace f538_for = 10.6 if _n==1

42 replace f538_Berr = 14.5 if _n==1

43 replace f538_Rerr = 6.7 if _n==1

44

45 ** "Minnesota"

46 replace f538_for = 9.1 if _n==2

47 replace f538_Berr = 12.1 if _n==2

48 replace f538_Rerr = 8.0 if _n==2

49

50 ** "Wisconsin"

51 replace f538_for = 8.3 if _n==3

52 replace f538_Berr = 11.6 if _n==3

53 replace f538_Rerr = 5.1 if _n==3

54

55 ** "Michigan"

56 replace f538_for = 8.0 if _n==4

57 replace f538_Berr = 11.2 if _n==4

58 replace f538_Rerr = 4.9

59

60 ** "Nevada"

61 replace f538_for = 6.1 if _n==5

62 replace f538_Berr = 9.5 if _n==5

63 replace f538_Rerr = 2.8 if _n==5

64

65 ** "Pennsylvania"

66 replace f538_for = 4.7 if _n==6

67 replace f538_Berr = 7.7 if _n==6

68 replace f538_Rerr = 1.7 if _n==6

69

70 ** "Arizona"

71 replace f538_for = 2.6 if _n==7

72 replace f538_Berr = 5.8 if _n==7

73 replace f538_Rerr = -0.7 if _n==7

74

Page 2 of 6


Untitled

12/3/20, 4:02 PM

74

75 ** "Florida"

76 replace f538_for = 2.5 if _n==8

77 replace f538_Berr = 5.7 if _n==8

78 replace f538_Rerr = -0.7 if _n==8

79

80 ** "North Carolina"

81 replace f538_for = 1.8 if _n==9

82 replace f538_Berr = 4.7 if _n==9

83 replace f538_Rerr = -1.1 if _n==9

84

85 ** "Georgia"

86 replace f538_for = 1 if _n==10

87 replace f538_Berr = 3.6 if _n==10

88 replace f538_Rerr = -1.6 if _n==10

89

90 ** "Ohio"

91 replace f538_for = -0.6 if _n==11

92 replace f538_Berr = 2.5 if _n==11

93 replace f538_Rerr = -3.7 if _n==11

94

95 ** "Iowa"

96 replace f538_for = -1.5 if _n==12

97 replace f538_Berr = 2 if _n==12

98 replace f538_Rerr = -5 if _n==12

99

100 ** "Texas"

101 replace f538_for = -1.5 if _n==13

102 replace f538_Berr = 1.7 if _n==13

103 replace f538_Rerr = -4.7 if _n==13

104

105 ** "Montana"

106 replace f538_for = -6.4 if _n==14

107 replace f538_Berr = -3.3 if _n==14

108 replace f538_Rerr = -9.5 if _n==14

109

110 ** "South Carolina"

111 replace f538_for = -7.5 if _n==15

112 replace f538_Berr = -4.8 if _n==15

Page 3 of 6


Untitled

12/3/20, 4:02 PM

112 replace f538_Berr = -4.8 if _n==15

113 replace f538_Rerr = -10.2 if _n==15

114

115 ** "Alaska"

116 replace f538_for = -8.5 if _n==16

117 replace f538_Berr = -5.3 if _n==16

118 replace f538_Rerr = -11.7 if _n==16

119

120 ** "Missouri"

121 replace f538_for = -9.4 if _n==17

122 replace f538_Berr = -6.3 if _n==17

123 replace f538_Rerr = -12.5 if _n==17

124

125

126

127 *====

128

129 gen part_res_b = .

130 gen part_res_t = .

131 gen more_99per = 0

132

133 ** "New Hampshire"

134 replace part_res_b = 52.9 if _n==1

135 replace part_res_t = 45.5 if _n==1

136 replace more_99per = 1 if _n==1

137

138 ** "Minnesota"

139 replace part_res_b = 52.6 if _n==2

140 replace part_res_t = 45.4 if _n==2

141 replace more_99per = 1 if _n==2

142

143 ** "Wisconsin"

144 replace part_res_b = 49.6 if _n==3

145 replace part_res_t = 48.9 if _n==3

146 replace more_99per = 1 if _n==3

147

148 ** "Michigan"

149 replace part_res_b = 50.6 if _n==4

150 replace part_res_t = 47.8 if _n==4

Page 4 of 6


Untitled

12/3/20, 4:02 PM

150 replace part_res_t = 47.8 if _n==4

151 replace more_99per = 1 if _n==4

152

153 ** "Nevada"

154 replace part_res_b = 50.1 if _n==5

155 replace part_res_t = 47.7 if _n==5

156 replace more_99per = 1 if _n==5

157

158 ** "Pennsylvania"

159 replace part_res_b = 50.0 if _n==6

160 replace part_res_t = 48.8 if _n==6

161 replace more_99per = 1 if _n==6

162

163 ** "Arizona"

164 replace part_res_b = 49.4 if _n==7

165 replace part_res_t = 49.1 if _n==7

166 replace more_99per = 1 if _n==7

167

168 ** "Florida"

169 replace part_res_b = 47.9 if _n==8

170 replace part_res_t = 51.2 if _n==8

171 replace more_99per = 1 if _n==8

172

173 ** "North Carolina"

174 replace part_res_b = 48.7 if _n==9

175 replace part_res_t = 50.1 if _n==9

176 replace more_99per = 1 if _n==9

177

178 ** "Georgia"

179 replace part_res_b = 49.5 if _n==10

180 replace part_res_t = 49.3 if _n==10

181 replace more_99per = 1 if _n==10

182

183 ** "Ohio"

184 replace part_res_b = 45.3 if _n==11

185 replace part_res_t = 53.3 if _n==11

186 replace more_99per = 1 if _n==11

187

188 ** "Iowa"

Page 5 of 6


Untitled

12/3/20, 4:02 PM

188 ** "Iowa"

189 replace part_res_b = 45.0 if _n==12

190 replace part_res_t = 53.2 if _n==12

191 replace more_99per = 1 if _n==12

192

193 ** "Texas"

194 replace part_res_b = 46.5 if _n==13

195 replace part_res_t = 52.1 if _n==13

196 replace more_99per = 1 if _n==13

197

198 ** "Montana"

199 replace part_res_b = 40.6 if _n==14

200 replace part_res_t = 56.9 if _n==14

201 replace more_99per = 1 if _n==14

202

203

204 ** "South Carolina"

205 replace part_res_b = 43.4 if _n==15

206 replace part_res_t = 55.1 if _n==15

207 replace more_99per = 1 if _n==15

208

209

210 ** "Alaska"

211 replace part_res_b = 43.0 if _n==16

212 replace part_res_t = 53.1 if _n==16

213 replace more_99per = 1 if _n==16

214

215 ** "Missouri"

216 replace part_res_b = 41.4 if _n==17

217 replace part_res_t = 56.8 if _n==17

218 replace more_99per = 1 if _n==17

219

220

221 * Margin of victory

222

223 gen b_mvic = part_res_b-part_res_t

224

225 *===============================================================

Page 6 of 6

More magazines by this user
Similar magazines