Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Code used for my paper "A dimensao geografica das eleicoes brasileiras".
* extracting variance estimates by state (to be used in R)
reg pt2 party lgdpcap bolsagdp rural illiteracy nonadequate AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO
predict double eps, residual
robvar eps, by(state)
by state, sort: egen sd_eps = sd(eps)
generate double gw_wt = 1/sd_eps^2
tabstat sd_eps gw_wt, by(state)
* running initial diagnostics (obs.: failed; too many observations for spatwmat)
summarize ycoord xcoord
display sqrt((2395.811 - -2144.938)^2 + (521.0405 - -3725.342)^2)
spatwmat, name(wminverse0) ycoord(ycoord) xcoord(xcoord) band(0 6300)
spatgsa pt2, weights(wminverse0) moran
spatlsa pt2, weights(wminverse0) moran map(election2010coordinates) xcoord(xcoord) ycoord(ycoord)
spatdiag pt2 party lgdpcap bolsagdp rural illiteracy nonadequate AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO, weights(wminverse0)
spatreg pt2 party lgdpcap bolsagdp rural illiteracy nonadequate AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO, weights(wminverse0) model(lag)
spatreg pt2 party lgdpcap bolsagdp rural illiteracy nonadequate AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO, weights(wminverse0) model(error)
* generating weights matrices
spmat contiguity wmqueen using election2010coordinates, id(_ID)
spmat idistance wminverse ycoord xcoord, id(_ID)
* estimating the spatial models
spreg gs2sls pt2 party lgdpcap bolsagdp rural illiteracy nonadequate AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO, id(_ID) het dlmat(wmqueen) elmat(wmqueen)
spreg gs2sls pt2 party lgdpcap bolsagdp rural illiteracy nonadequate AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO, id(_ID) het dlmat(wminverse) elmat(wminverse)
spreg ml pt2 party lgdpcap bolsagdp rural illiteracy nonadequate AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO, id(_ID) dlmat(wmqueen) elmat(wmqueen)
spreg ml pt2 party lgdpcap bolsagdp rural illiteracy nonadequate AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO, id(_ID) dlmat(wminverse) elmat(wminverse)
constraint define 1 [lambda]_cons=0
spreg ml pt2 party lgdpcap bolsagdp rural illiteracy nonadequate AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO, id(_ID) dlmat(wmqueen) elmat(wmqueen) constraints(1)
spreg ml pt2 party lgdpcap bolsagdp rural illiteracy nonadequate AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO, id(_ID) dlmat(wminverse) elmat(wminverse) constraints(1)
* GWR (obs.: failed)
gwr pt2 party lgdpcap bolsagdp rural illiteracy nonadequate, east(xcoord) north(ycoord) bandwidth(174.31)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment