File: us-2020.inp

package info (click to toggle)
gretl 2022c-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 59,552 kB
  • sloc: ansic: 409,074; sh: 4,449; makefile: 3,222; cpp: 2,777; xml: 599; perl: 364
file content (35 lines) | stat: -rw-r--r-- 1,032 bytes parent folder | download
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
include geoplot.gfn

open us-states.geojson --quiet --frompkg=geoplot
bundle b = bread($mapfile)

# Shrink Alaska and place underneath the "lower 48"
matrix shift = {34, -35}
matrix center = {-150.885, 62.5503}
matrix scale = {0.3, 0.35}
geoplot_translate_feature(&b, 48, shift, center, scale)

# Shift Hawaii alongside Alaska
shift = {51, 5}
geoplot_translate_feature(&b, 5, shift)

bwrite(b, "us-rearranged.geojson")
open us-rearranged.geojson

# Add per-state Democratic-win dummy
strings dem_states = defarray("WA", "OR", "CA", "NV", "AZ", "NM",
"CO", "MN", "WI", "IL", "MI", "GA", "VA", "PA", "NY", "VT", "NH",
"ME", "MA", "RI", "CT", "NJ", "DE", "MD", "DC", "HI")
series D = 0
loop i=1..$nobs
   if nelem(instrings(dem_states, iso_3166_2[i] + 3))
      D[i] = 1
   endif
endloop

# Display electoral map
bundle opts = _(plotfile = "us0.plt", title = "USA, 2020")
opts.palette = "set palette maxcolors 2; \
set palette defined (0 '#D22532', 1 '#244999'); unset colorbox"
opts.projection = "EPSG2163"
geoplot($mapfile, D, opts)