using Pkg
Pkg.activate(".")

using DataFrames, CSV, StatsPlots, Downloads, DataFramesMeta, Dates, Statistics
using Turing, Memoization, ReverseDiff, Serialization
using LinearAlgebra, Distributions
  Activating project at `~/Consulting/LakelandAppliedSciLLC/CriminologyGuns`

Constitutional Carry

The most recent trend in firearms carry in the US is the conversion of “shall issue” states to a permitless carry system. In this system everyone over a certain age (18 or 21 depending on state) who is legally able to possess a pistol may carry that pistol concealed in public subject to relatively few restrictions (such as not allowed in secure areas with metal detectors etc). For the moment we ignore the issue of “open carry” which has different issues such as intimidation purposes.

Of all the systems for regulating firearms in public, this is the least restrictive. There are various models one might have of how this would affect gun homicides. Some might argue armed citizens deter crime, others might argue it makes it easier to commit crime, others might argue the effect if any would be minimal as criminals were already carrying guns and only relatively “model citizens” would start carrying, and they are generally not involved in crime in terms of committing them or as victims. It’s worthwhile to look at the data to see what hypotheses are comopatible with the observed trends.

We plot firearms homicide rates through time for each state. We place a vertical red line at the point in time where the constitutional carry law was signed if any.

concarry = leftjoin(fipscodes,CSV.read("./data/ConstCarryDates.csv",DataFrame),on = :STUSAB => :StateCode)
concarry.date = map(x -> ismissing(x) ? missing : Date(div(x,10000),div(mod(x,10000),100),1),concarry.LawDate)
concarry.year = map(x -> ismissing(x) ? missing : year(x),concarry.date)
concarry = @subset(concarry,:STATE .<= 59) #ignore minor territories

let p = []
    for (st,stusab,statename,statens,lawdate,stdate,year) in eachrow(concarry)
        d = year
        sub = @subset(joined,:state .== statename)
        if(nrow(sub) > 0)
            pp = plot(sub.year,sub.crudedeathrate,ylim=(0,15),size=(500,500),
                title="$statename\nhomicides",xlab="Year",ylab="Gun Homicide/100k/yr",legend=false)
            if(!ismissing(d))
                pp = plot!([(d,0),(d,15)])
            end
        push!(p,pp)
        end
    end
    display(plot(p...; size = (2000,2000)))
end

States by Geographic Group

Looking at the raw data we can see that there are a number of states that have an “accelerating” trend of increased firearms homicide violence in the period from about mid 2014 to 2015 onward. Some of these have converted to Constitutional Carry near the beginning of that period or during that period, with the trend beginning before the carry provision for several of the states. Also many states have passed their laws in the last few years and have no data post-law.

Let’s look at these states grouped into geographic regions, because trends in regions may be more obvious. We will start with the following groupings:

stategroups = [["WA","OR","CA","NV","AZ"],["ID","MT","WY","UT","CO","NM","TX"],["ND","SD","NE","KS","OK","IA","MO"],
    ["MN","WI","IL","IN","MI","OH"],["AR","LA","MS","AL","GA","FL","SC"],["TN","NC","KY","WV","VA","MD","DE"],
    ["PA","NJ","NY","CT","RI","MA","VT","NH","ME"],["AK","HI","DC"]]

stategroupdf = DataFrame(STUSAB = reduce(vcat,stategroups),stgroup = reduce(vcat,[[k for j in 1:length(stategroups[k])] for k in 1:length(stategroups)]))
stategroupdf = leftjoin(fipscodes,stategroupdf; on = :STUSAB)

@assert(length(unique(reduce(vcat,stategroups))) == 51) # 50 states plus DC

let p1 = [], p2=[]
    for statelist in stategroups
        sub = joined[in.(joined.STUSAB, Ref(statelist)),:]
        ccdates = @chain @subset(concarry, in.(concarry.STUSAB,Ref(statelist))) begin
            @subset(.! ismissing.(:year))
        end
        
        ccdatesenact = leftjoin(ccdates,sub, on = [:STUSAB => :STUSAB, :year => :year], makeunique = true)
        ccdatesenact = @subset(ccdatesenact, .! ismissing.(:crudedeathrate))
        #display(ccdatesenact)
        #display(sub)
        p = plot(sub.year,sub.crudedeathrate,group=sub.STUSAB,ylim=(0,20),legend=:topleft,linewidth = 3, thickness_scaling=1,
            ylab="Homicides/100k population/yr",xlab="Year")
        if nrow(ccdatesenact) > 0
            p = scatter!(ccdatesenact.year,ccdatesenact.crudedeathrate,markersize=6,group = ccdatesenact.STUSAB)
        end
        push!(p1,p)
        p = plot(sub.cumgunrate,sub.crudedeathrate,markersize=6,linewidth=3,thickness_scaling=1, xlab="Gun Ownership (guns/person)", ylab="Homicide rate (per 100k)", group=sub.STUSAB)
        push!(p2,p)
    end
    display(plot(p1...; size=(1000,1000)))
    display(plot(p2...; size=(1000,1000)))
end

States by Relative Change

Each state has its own overall level of firearm violence, but often trends in the same direction relative to its region even if its overall level is higher or lower. This suggests a model in which we measure each state using a dimensionless number relative to some baseline level. For example the average rate in the years 1999,2000,2001

baselines = @chain joined begin
    @subset(in.(:year,Ref((1999,2000,2001))))
    @by(:STUSAB, :baseline = mean(:crudedeathrate))
end

bljoined = @chain leftjoin(stategroupdf,leftjoin(baselines,joined,on = :STUSAB, makeunique=true),on=:STUSAB,makeunique=true) begin
    @subset(.! ismissing.(:crudedeathrate))
    @orderby(:stgroup,:STUSAB,:year)
end

function getccd(gr)
    ccd = innerjoin(gr,@subset(concarry,.! ismissing.(:year)), on = [:STUSAB => :STUSAB, :year => :year], makeunique = true)
    ccd = @subset(ccd, .! ismissing.(:crudedeathrate))
    ccd
end

function makerelplot(gr)
    ccd = getccd(gr)
#    display(ccd)
    p = plot(gr.year,gr.crudedeathrate ./ gr.baseline,group=gr.STUSAB,legend=:topleft,ylim=(0.0,2.5),xlab="Year",ylab="Relative Rate") 
    if nrow(ccd) == 1
        scatter!(ccd.year,ccd.crudedeathrate ./ ccd.baseline)
    elseif nrow(ccd) > 1 
        scatter!(ccd.year,ccd.crudedeathrate ./ ccd.baseline,group = ccd.STUSAB)
    end
    p
end
makerelplot (generic function with 1 method)

What has been the relative change?

Each state plotted in a group with other geographically similar states. Firearm homicide rate relative to average recorded rate 1999-2001.

plots = [makerelplot(gr)
    for gr in groupby(bljoined,:stgroup)]
    
plot(plots... ; size=(1000,1000),linewidth=2,xlab="Year",ylab="Relative Rate")

Modeling the process with Bayesian Models

We can try to estimate the effects of these laws by building a model of the overall process. Because we can’t resurrect people from the dead, the homicide rate can never be negative. It makes sense then to model the homicide rate on a logarithmic scale.

We estimate the behavior of the states as an overall level, plus a shape that is common to the region. Individual states are then allowed a small perturbation to the regional shape.

This small perturbation method was the only way that seemed to make sense to estimate the counterfactual. Clearly none of the states will perform exactly like the average. So if we use the regional average, we will bias towards a lot of noise. Obviously, there is no effect if no law was passed, so for those states with no law passed, the counterfactual is the same as the actual, and we then should allow a size of perturbation which allows the function to fit the actuals for those states. By modifying the parameter statecoefpert we can make it as small as possible while still causing all the non-law states to fit reasonably well. At this point whatever lack of fit there is post-law in those states, could be at least partially attributed to the law. The choice of value of log(1.25)/2.0 ~ 0.112 seemed to fit the bill, leaving only Maryland the only non-law not quite well fit by the model. Any smaller value left both MD and NY fitting poorly.

The effect of constitutional carry law would then be estimated as the log firearm homicide rate which exceeds the state level counterfactual estimate in the years after the passage of the law, with a transient onset curve included in the model.

We impose an informal smoothness requirement on the counterfactual estimates by using a compact radial basis function expansion with one center every 4 years, and a maximum radius of 7 years so that there is overlap between adjacent centers.

function bumpfun(x,c,scale)
    stdx = (x-c)/scale
    if stdx < -1.0 || stdx > 1.0
        0.0
    else
        exp(1.0-1.0/(1.0-stdx^2)) # goes to zero at -1 and 1, and 1 at x=0
    end
end

function timeser(x,coefs,centers,scale)
    f = 0.0
    for (a,c) in Iterators.zip(coefs,centers)
        f += a*bumpfun(x,c,scale)
    end
    return f
end

function laweffect(yr,rate,start)
    if yr >= start
        1.0-exp(-rate*(yr-start))
    else   
        0.0
    end
end


statecoefpert = log(1.25)/2.0

include("model.jl") ## load the model, this is a separate file so we can save the output unless it changes

modeljoined = @chain leftjoin(joined,stategroupdf; on = :STUSAB, makeunique=true) begin
    @subset(.! ismissing.(:crudedeathrate))
end

lawdates = @chain leftjoin(DataFrame(STATE=1:55),concarry; on=:STATE) begin
    @subset(:STATE .< 60)
    @rtransform(:year = ismissing(:year) ? 3000 : :year)
    @orderby(:STATE)
end

centers = [i for i in (minimum(modeljoined.year)-4):4:(maximum(modeljoined.year)+4)]
width = 7.0


modl = guns(modeljoined.StateCode,maximum(modeljoined.StateCode),modeljoined.stgroup,maximum(modeljoined.stgroup),
        centers, width, modeljoined.year,log.(modeljoined.crudedeathrate),lawdates.year,statecoefpert)

setadbackend(:reversediff)
Turing.setrdcache(true)

savedfile = "./saved/samples.dat"
global s = []
if stat(savedfile).mtime > stat("./model.jl").mtime
    global s = deserialize(savedfile)
else
    global s = sample(modl,NUTS(500,0.8),MCMCThreads(),500,3)
    serialize(savedfile,s)
end
Chains MCMC chain (500×957×3 Array{Float64, 3}):
Iterations        = 1:1:500
Number of chains  = 3
Samples per chain = 500
parameters        = lawrate, meanlawcoef, nationcoefs[1], nationcoefs[2], nationcoefs[3], nationcoefs[4], nationcoefs[5], nationcoefs[6], nationcoefs[7], nationcoefs[8], nationcoefs[9], nationcoefs[10], nationcoefs[11], nationcoefs[12], nationcoefs[13], regioncoefs[1][1], regioncoefs[1][2], regioncoefs[1][3], regioncoefs[1][4], regioncoefs[1][5], regioncoefs[1][6], regioncoefs[1][7], regioncoefs[1][8], regioncoefs[1][9], regioncoefs[1][10], regioncoefs[1][11], regioncoefs[1][12], regioncoefs[1][13], regioncoefs[2][1], regioncoefs[2][2], regioncoefs[2][3], regioncoefs[2][4], regioncoefs[2][5], regioncoefs[2][6], regioncoefs[2][7], regioncoefs[2][8], regioncoefs[2][9], regioncoefs[2][10], regioncoefs[2][11], regioncoefs[2][12], regioncoefs[2][13], regioncoefs[3][1], regioncoefs[3][2], regioncoefs[3][3], regioncoefs[3][4], regioncoefs[3][5], regioncoefs[3][6], regioncoefs[3][7], regioncoefs[3][8], regioncoefs[3][9], regioncoefs[3][10], regioncoefs[3][11], regioncoefs[3][12], regioncoefs[3][13], regioncoefs[4][1], regioncoefs[4][2], regioncoefs[4][3], regioncoefs[4][4], regioncoefs[4][5], regioncoefs[4][6], regioncoefs[4][7], regioncoefs[4][8], regioncoefs[4][9], regioncoefs[4][10], regioncoefs[4][11], regioncoefs[4][12], regioncoefs[4][13], regioncoefs[5][1], regioncoefs[5][2], regioncoefs[5][3], regioncoefs[5][4], regioncoefs[5][5], regioncoefs[5][6], regioncoefs[5][7], regioncoefs[5][8], regioncoefs[5][9], regioncoefs[5][10], regioncoefs[5][11], regioncoefs[5][12], regioncoefs[5][13], regioncoefs[6][1], regioncoefs[6][2], regioncoefs[6][3], regioncoefs[6][4], regioncoefs[6][5], regioncoefs[6][6], regioncoefs[6][7], regioncoefs[6][8], regioncoefs[6][9], regioncoefs[6][10], regioncoefs[6][11], regioncoefs[6][12], regioncoefs[6][13], regioncoefs[7][1], regioncoefs[7][2], regioncoefs[7][3], regioncoefs[7][4], regioncoefs[7][5], regioncoefs[7][6], regioncoefs[7][7], regioncoefs[7][8], regioncoefs[7][9], regioncoefs[7][10], regioncoefs[7][11], regioncoefs[7][12], regioncoefs[7][13], regioncoefs[8][1], regioncoefs[8][2], regioncoefs[8][3], regioncoefs[8][4], regioncoefs[8][5], regioncoefs[8][6], regioncoefs[8][7], regioncoefs[8][8], regioncoefs[8][9], regioncoefs[8][10], regioncoefs[8][11], regioncoefs[8][12], regioncoefs[8][13], scale, statebase[1], statebase[2], statebase[3], statebase[4], statebase[5], statebase[6], statebase[7], statebase[8], statebase[9], statebase[10], statebase[11], statebase[12], statebase[13], statebase[14], statebase[15], statebase[16], statebase[17], statebase[18], statebase[19], statebase[20], statebase[21], statebase[22], statebase[23], statebase[24], statebase[25], statebase[26], statebase[27], statebase[28], statebase[29], statebase[30], statebase[31], statebase[32], statebase[33], statebase[34], statebase[35], statebase[36], statebase[37], statebase[38], statebase[39], statebase[40], statebase[41], statebase[42], statebase[43], statebase[44], statebase[45], statebase[46], statebase[47], statebase[48], statebase[49], statebase[50], statebase[51], statebase[52], statebase[53], statebase[54], statebase[55], statecoefs[1][1], statecoefs[1][2], statecoefs[1][3], statecoefs[1][4], statecoefs[1][5], statecoefs[1][6], statecoefs[1][7], statecoefs[1][8], statecoefs[1][9], statecoefs[1][10], statecoefs[1][11], statecoefs[1][12], statecoefs[1][13], statecoefs[2][1], statecoefs[2][2], statecoefs[2][3], statecoefs[2][4], statecoefs[2][5], statecoefs[2][6], statecoefs[2][7], statecoefs[2][8], statecoefs[2][9], statecoefs[2][10], statecoefs[2][11], statecoefs[2][12], statecoefs[2][13], statecoefs[3][1], statecoefs[3][2], statecoefs[3][3], statecoefs[3][4], statecoefs[3][5], statecoefs[3][6], statecoefs[3][7], statecoefs[3][8], statecoefs[3][9], statecoefs[3][10], statecoefs[3][11], statecoefs[3][12], statecoefs[3][13], statecoefs[4][1], statecoefs[4][2], statecoefs[4][3], statecoefs[4][4], statecoefs[4][5], statecoefs[4][6], statecoefs[4][7], statecoefs[4][8], statecoefs[4][9], statecoefs[4][10], statecoefs[4][11], statecoefs[4][12], statecoefs[4][13], statecoefs[5][1], statecoefs[5][2], statecoefs[5][3], statecoefs[5][4], statecoefs[5][5], statecoefs[5][6], statecoefs[5][7], statecoefs[5][8], statecoefs[5][9], statecoefs[5][10], statecoefs[5][11], statecoefs[5][12], statecoefs[5][13], statecoefs[6][1], statecoefs[6][2], statecoefs[6][3], statecoefs[6][4], statecoefs[6][5], statecoefs[6][6], statecoefs[6][7], statecoefs[6][8], statecoefs[6][9], statecoefs[6][10], statecoefs[6][11], statecoefs[6][12], statecoefs[6][13], statecoefs[7][1], statecoefs[7][2], statecoefs[7][3], statecoefs[7][4], statecoefs[7][5], statecoefs[7][6], statecoefs[7][7], statecoefs[7][8], statecoefs[7][9], statecoefs[7][10], statecoefs[7][11], statecoefs[7][12], statecoefs[7][13], statecoefs[8][1], statecoefs[8][2], statecoefs[8][3], statecoefs[8][4], statecoefs[8][5], statecoefs[8][6], statecoefs[8][7], statecoefs[8][8], statecoefs[8][9], statecoefs[8][10], statecoefs[8][11], statecoefs[8][12], statecoefs[8][13], statecoefs[9][1], statecoefs[9][2], statecoefs[9][3], statecoefs[9][4], statecoefs[9][5], statecoefs[9][6], statecoefs[9][7], statecoefs[9][8], statecoefs[9][9], statecoefs[9][10], statecoefs[9][11], statecoefs[9][12], statecoefs[9][13], statecoefs[10][1], statecoefs[10][2], statecoefs[10][3], statecoefs[10][4], statecoefs[10][5], statecoefs[10][6], statecoefs[10][7], statecoefs[10][8], statecoefs[10][9], statecoefs[10][10], statecoefs[10][11], statecoefs[10][12], statecoefs[10][13], statecoefs[11][1], statecoefs[11][2], statecoefs[11][3], statecoefs[11][4], statecoefs[11][5], statecoefs[11][6], statecoefs[11][7], statecoefs[11][8], statecoefs[11][9], statecoefs[11][10], statecoefs[11][11], statecoefs[11][12], statecoefs[11][13], statecoefs[12][1], statecoefs[12][2], statecoefs[12][3], statecoefs[12][4], statecoefs[12][5], statecoefs[12][6], statecoefs[12][7], statecoefs[12][8], statecoefs[12][9], statecoefs[12][10], statecoefs[12][11], statecoefs[12][12], statecoefs[12][13], statecoefs[13][1], statecoefs[13][2], statecoefs[13][3], statecoefs[13][4], statecoefs[13][5], statecoefs[13][6], statecoefs[13][7], statecoefs[13][8], statecoefs[13][9], statecoefs[13][10], statecoefs[13][11], statecoefs[13][12], statecoefs[13][13], statecoefs[14][1], statecoefs[14][2], statecoefs[14][3], statecoefs[14][4], statecoefs[14][5], statecoefs[14][6], statecoefs[14][7], statecoefs[14][8], statecoefs[14][9], statecoefs[14][10], statecoefs[14][11], statecoefs[14][12], statecoefs[14][13], statecoefs[15][1], statecoefs[15][2], statecoefs[15][3], statecoefs[15][4], statecoefs[15][5], statecoefs[15][6], statecoefs[15][7], statecoefs[15][8], statecoefs[15][9], statecoefs[15][10], statecoefs[15][11], statecoefs[15][12], statecoefs[15][13], statecoefs[16][1], statecoefs[16][2], statecoefs[16][3], statecoefs[16][4], statecoefs[16][5], statecoefs[16][6], statecoefs[16][7], statecoefs[16][8], statecoefs[16][9], statecoefs[16][10], statecoefs[16][11], statecoefs[16][12], statecoefs[16][13], statecoefs[17][1], statecoefs[17][2], statecoefs[17][3], statecoefs[17][4], statecoefs[17][5], statecoefs[17][6], statecoefs[17][7], statecoefs[17][8], statecoefs[17][9], statecoefs[17][10], statecoefs[17][11], statecoefs[17][12], statecoefs[17][13], statecoefs[18][1], statecoefs[18][2], statecoefs[18][3], statecoefs[18][4], statecoefs[18][5], statecoefs[18][6], statecoefs[18][7], statecoefs[18][8], statecoefs[18][9], statecoefs[18][10], statecoefs[18][11], statecoefs[18][12], statecoefs[18][13], statecoefs[19][1], statecoefs[19][2], statecoefs[19][3], statecoefs[19][4], statecoefs[19][5], statecoefs[19][6], statecoefs[19][7], statecoefs[19][8], statecoefs[19][9], statecoefs[19][10], statecoefs[19][11], statecoefs[19][12], statecoefs[19][13], statecoefs[20][1], statecoefs[20][2], statecoefs[20][3], statecoefs[20][4], statecoefs[20][5], statecoefs[20][6], statecoefs[20][7], statecoefs[20][8], statecoefs[20][9], statecoefs[20][10], statecoefs[20][11], statecoefs[20][12], statecoefs[20][13], statecoefs[21][1], statecoefs[21][2], statecoefs[21][3], statecoefs[21][4], statecoefs[21][5], statecoefs[21][6], statecoefs[21][7], statecoefs[21][8], statecoefs[21][9], statecoefs[21][10], statecoefs[21][11], statecoefs[21][12], statecoefs[21][13], statecoefs[22][1], statecoefs[22][2], statecoefs[22][3], statecoefs[22][4], statecoefs[22][5], statecoefs[22][6], statecoefs[22][7], statecoefs[22][8], statecoefs[22][9], statecoefs[22][10], statecoefs[22][11], statecoefs[22][12], statecoefs[22][13], statecoefs[23][1], statecoefs[23][2], statecoefs[23][3], statecoefs[23][4], statecoefs[23][5], statecoefs[23][6], statecoefs[23][7], statecoefs[23][8], statecoefs[23][9], statecoefs[23][10], statecoefs[23][11], statecoefs[23][12], statecoefs[23][13], statecoefs[24][1], statecoefs[24][2], statecoefs[24][3], statecoefs[24][4], statecoefs[24][5], statecoefs[24][6], statecoefs[24][7], statecoefs[24][8], statecoefs[24][9], statecoefs[24][10], statecoefs[24][11], statecoefs[24][12], statecoefs[24][13], statecoefs[25][1], statecoefs[25][2], statecoefs[25][3], statecoefs[25][4], statecoefs[25][5], statecoefs[25][6], statecoefs[25][7], statecoefs[25][8], statecoefs[25][9], statecoefs[25][10], statecoefs[25][11], statecoefs[25][12], statecoefs[25][13], statecoefs[26][1], statecoefs[26][2], statecoefs[26][3], statecoefs[26][4], statecoefs[26][5], statecoefs[26][6], statecoefs[26][7], statecoefs[26][8], statecoefs[26][9], statecoefs[26][10], statecoefs[26][11], statecoefs[26][12], statecoefs[26][13], statecoefs[27][1], statecoefs[27][2], statecoefs[27][3], statecoefs[27][4], statecoefs[27][5], statecoefs[27][6], statecoefs[27][7], statecoefs[27][8], statecoefs[27][9], statecoefs[27][10], statecoefs[27][11], statecoefs[27][12], statecoefs[27][13], statecoefs[28][1], statecoefs[28][2], statecoefs[28][3], statecoefs[28][4], statecoefs[28][5], statecoefs[28][6], statecoefs[28][7], statecoefs[28][8], statecoefs[28][9], statecoefs[28][10], statecoefs[28][11], statecoefs[28][12], statecoefs[28][13], statecoefs[29][1], statecoefs[29][2], statecoefs[29][3], statecoefs[29][4], statecoefs[29][5], statecoefs[29][6], statecoefs[29][7], statecoefs[29][8], statecoefs[29][9], statecoefs[29][10], statecoefs[29][11], statecoefs[29][12], statecoefs[29][13], statecoefs[30][1], statecoefs[30][2], statecoefs[30][3], statecoefs[30][4], statecoefs[30][5], statecoefs[30][6], statecoefs[30][7], statecoefs[30][8], statecoefs[30][9], statecoefs[30][10], statecoefs[30][11], statecoefs[30][12], statecoefs[30][13], statecoefs[31][1], statecoefs[31][2], statecoefs[31][3], statecoefs[31][4], statecoefs[31][5], statecoefs[31][6], statecoefs[31][7], statecoefs[31][8], statecoefs[31][9], statecoefs[31][10], statecoefs[31][11], statecoefs[31][12], statecoefs[31][13], statecoefs[32][1], statecoefs[32][2], statecoefs[32][3], statecoefs[32][4], statecoefs[32][5], statecoefs[32][6], statecoefs[32][7], statecoefs[32][8], statecoefs[32][9], statecoefs[32][10], statecoefs[32][11], statecoefs[32][12], statecoefs[32][13], statecoefs[33][1], statecoefs[33][2], statecoefs[33][3], statecoefs[33][4], statecoefs[33][5], statecoefs[33][6], statecoefs[33][7], statecoefs[33][8], statecoefs[33][9], statecoefs[33][10], statecoefs[33][11], statecoefs[33][12], statecoefs[33][13], statecoefs[34][1], statecoefs[34][2], statecoefs[34][3], statecoefs[34][4], statecoefs[34][5], statecoefs[34][6], statecoefs[34][7], statecoefs[34][8], statecoefs[34][9], statecoefs[34][10], statecoefs[34][11], statecoefs[34][12], statecoefs[34][13], statecoefs[35][1], statecoefs[35][2], statecoefs[35][3], statecoefs[35][4], statecoefs[35][5], statecoefs[35][6], statecoefs[35][7], statecoefs[35][8], statecoefs[35][9], statecoefs[35][10], statecoefs[35][11], statecoefs[35][12], statecoefs[35][13], statecoefs[36][1], statecoefs[36][2], statecoefs[36][3], statecoefs[36][4], statecoefs[36][5], statecoefs[36][6], statecoefs[36][7], statecoefs[36][8], statecoefs[36][9], statecoefs[36][10], statecoefs[36][11], statecoefs[36][12], statecoefs[36][13], statecoefs[37][1], statecoefs[37][2], statecoefs[37][3], statecoefs[37][4], statecoefs[37][5], statecoefs[37][6], statecoefs[37][7], statecoefs[37][8], statecoefs[37][9], statecoefs[37][10], statecoefs[37][11], statecoefs[37][12], statecoefs[37][13], statecoefs[38][1], statecoefs[38][2], statecoefs[38][3], statecoefs[38][4], statecoefs[38][5], statecoefs[38][6], statecoefs[38][7], statecoefs[38][8], statecoefs[38][9], statecoefs[38][10], statecoefs[38][11], statecoefs[38][12], statecoefs[38][13], statecoefs[39][1], statecoefs[39][2], statecoefs[39][3], statecoefs[39][4], statecoefs[39][5], statecoefs[39][6], statecoefs[39][7], statecoefs[39][8], statecoefs[39][9], statecoefs[39][10], statecoefs[39][11], statecoefs[39][12], statecoefs[39][13], statecoefs[40][1], statecoefs[40][2], statecoefs[40][3], statecoefs[40][4], statecoefs[40][5], statecoefs[40][6], statecoefs[40][7], statecoefs[40][8], statecoefs[40][9], statecoefs[40][10], statecoefs[40][11], statecoefs[40][12], statecoefs[40][13], statecoefs[41][1], statecoefs[41][2], statecoefs[41][3], statecoefs[41][4], statecoefs[41][5], statecoefs[41][6], statecoefs[41][7], statecoefs[41][8], statecoefs[41][9], statecoefs[41][10], statecoefs[41][11], statecoefs[41][12], statecoefs[41][13], statecoefs[42][1], statecoefs[42][2], statecoefs[42][3], statecoefs[42][4], statecoefs[42][5], statecoefs[42][6], statecoefs[42][7], statecoefs[42][8], statecoefs[42][9], statecoefs[42][10], statecoefs[42][11], statecoefs[42][12], statecoefs[42][13], statecoefs[43][1], statecoefs[43][2], statecoefs[43][3], statecoefs[43][4], statecoefs[43][5], statecoefs[43][6], statecoefs[43][7], statecoefs[43][8], statecoefs[43][9], statecoefs[43][10], statecoefs[43][11], statecoefs[43][12], statecoefs[43][13], statecoefs[44][1], statecoefs[44][2], statecoefs[44][3], statecoefs[44][4], statecoefs[44][5], statecoefs[44][6], statecoefs[44][7], statecoefs[44][8], statecoefs[44][9], statecoefs[44][10], statecoefs[44][11], statecoefs[44][12], statecoefs[44][13], statecoefs[45][1], statecoefs[45][2], statecoefs[45][3], statecoefs[45][4], statecoefs[45][5], statecoefs[45][6], statecoefs[45][7], statecoefs[45][8], statecoefs[45][9], statecoefs[45][10], statecoefs[45][11], statecoefs[45][12], statecoefs[45][13], statecoefs[46][1], statecoefs[46][2], statecoefs[46][3], statecoefs[46][4], statecoefs[46][5], statecoefs[46][6], statecoefs[46][7], statecoefs[46][8], statecoefs[46][9], statecoefs[46][10], statecoefs[46][11], statecoefs[46][12], statecoefs[46][13], statecoefs[47][1], statecoefs[47][2], statecoefs[47][3], statecoefs[47][4], statecoefs[47][5], statecoefs[47][6], statecoefs[47][7], statecoefs[47][8], statecoefs[47][9], statecoefs[47][10], statecoefs[47][11], statecoefs[47][12], statecoefs[47][13], statecoefs[48][1], statecoefs[48][2], statecoefs[48][3], statecoefs[48][4], statecoefs[48][5], statecoefs[48][6], statecoefs[48][7], statecoefs[48][8], statecoefs[48][9], statecoefs[48][10], statecoefs[48][11], statecoefs[48][12], statecoefs[48][13], statecoefs[49][1], statecoefs[49][2], statecoefs[49][3], statecoefs[49][4], statecoefs[49][5], statecoefs[49][6], statecoefs[49][7], statecoefs[49][8], statecoefs[49][9], statecoefs[49][10], statecoefs[49][11], statecoefs[49][12], statecoefs[49][13], statecoefs[50][1], statecoefs[50][2], statecoefs[50][3], statecoefs[50][4], statecoefs[50][5], statecoefs[50][6], statecoefs[50][7], statecoefs[50][8], statecoefs[50][9], statecoefs[50][10], statecoefs[50][11], statecoefs[50][12], statecoefs[50][13], statecoefs[51][1], statecoefs[51][2], statecoefs[51][3], statecoefs[51][4], statecoefs[51][5], statecoefs[51][6], statecoefs[51][7], statecoefs[51][8], statecoefs[51][9], statecoefs[51][10], statecoefs[51][11], statecoefs[51][12], statecoefs[51][13], statecoefs[52][1], statecoefs[52][2], statecoefs[52][3], statecoefs[52][4], statecoefs[52][5], statecoefs[52][6], statecoefs[52][7], statecoefs[52][8], statecoefs[52][9], statecoefs[52][10], statecoefs[52][11], statecoefs[52][12], statecoefs[52][13], statecoefs[53][1], statecoefs[53][2], statecoefs[53][3], statecoefs[53][4], statecoefs[53][5], statecoefs[53][6], statecoefs[53][7], statecoefs[53][8], statecoefs[53][9], statecoefs[53][10], statecoefs[53][11], statecoefs[53][12], statecoefs[53][13], statecoefs[54][1], statecoefs[54][2], statecoefs[54][3], statecoefs[54][4], statecoefs[54][5], statecoefs[54][6], statecoefs[54][7], statecoefs[54][8], statecoefs[54][9], statecoefs[54][10], statecoefs[54][11], statecoefs[54][12], statecoefs[54][13], statecoefs[55][1], statecoefs[55][2], statecoefs[55][3], statecoefs[55][4], statecoefs[55][5], statecoefs[55][6], statecoefs[55][7], statecoefs[55][8], statecoefs[55][9], statecoefs[55][10], statecoefs[55][11], statecoefs[55][12], statecoefs[55][13], statelawcoef[1], statelawcoef[2], statelawcoef[3], statelawcoef[4], statelawcoef[5], statelawcoef[6], statelawcoef[7], statelawcoef[8], statelawcoef[9], statelawcoef[10], statelawcoef[11], statelawcoef[12], statelawcoef[13], statelawcoef[14], statelawcoef[15], statelawcoef[16], statelawcoef[17], statelawcoef[18], statelawcoef[19], statelawcoef[20], statelawcoef[21], statelawcoef[22], statelawcoef[23], statelawcoef[24], statelawcoef[25], statelawcoef[26], statelawcoef[27], statelawcoef[28], statelawcoef[29], statelawcoef[30], statelawcoef[31], statelawcoef[32], statelawcoef[33], statelawcoef[34], statelawcoef[35], statelawcoef[36], statelawcoef[37], statelawcoef[38], statelawcoef[39], statelawcoef[40], statelawcoef[41], statelawcoef[42], statelawcoef[43], statelawcoef[44], statelawcoef[45], statelawcoef[46], statelawcoef[47], statelawcoef[48], statelawcoef[49], statelawcoef[50], statelawcoef[51], statelawcoef[52], statelawcoef[53], statelawcoef[54], statelawcoef[55]
internals         = acceptance_rate, hamiltonian_energy, hamiltonian_energy_error, is_accept, log_density, lp, max_hamiltonian_energy_error, n_steps, nom_step_size, numerical_error, step_size, tree_depth
Summary Statistics
          parameters      mean       std   naive_se      mcse         ess                  Symbol   Float64   Float64    Float64   Float64     Float64   Fl ⋯
             lawrate    3.8170    1.6859     0.0435    0.0290   4401.7156    0 ⋯
         meanlawcoef    0.0801    0.0743     0.0019    0.0022   1550.7673    0 ⋯
      nationcoefs[1]    0.0413    0.6867     0.0177    0.0118   5151.1657    0 ⋯
      nationcoefs[2]    0.1072    0.6759     0.0175    0.0110   5355.9487    0 ⋯
      nationcoefs[3]    0.0781    0.6578     0.0170    0.0107   3715.4405    0 ⋯
      nationcoefs[4]   -0.1930    0.6825     0.0176    0.0120   6023.9144    0 ⋯
      nationcoefs[5]    0.2366    0.6622     0.0171    0.0113   3495.8956    0 ⋯
      nationcoefs[6]    0.0435    0.6878     0.0178    0.0123   3774.1711    0 ⋯
      nationcoefs[7]   -0.1013    0.6663     0.0172    0.0124   2997.4910    0 ⋯
      nationcoefs[8]   -0.0672    0.6196     0.0160    0.0122   3948.0602    0 ⋯
      nationcoefs[9]   -0.0805    0.6410     0.0166    0.0116   3932.8216    0 ⋯
     nationcoefs[10]   -0.1387    0.6824     0.0176    0.0122   3352.7558    0 ⋯
     nationcoefs[11]   -0.2410    0.6789     0.0175    0.0091   3833.5662    0 ⋯
     nationcoefs[12]    0.1704    0.6991     0.0181    0.0117   4266.2348    1 ⋯
     nationcoefs[13]   -0.0343    0.6660     0.0172    0.0117   3787.7307    0 ⋯
   regioncoefs[1][1]    0.0463    0.1469     0.0038    0.0047    966.7836    1 ⋯
   regioncoefs[1][2]    0.0055    0.1368     0.0035    0.0043    760.7266    0 ⋯
   regioncoefs[1][3]    0.1845    0.1378     0.0036    0.0052    706.6964    1 ⋯
   regioncoefs[1][4]   -0.3022    0.1296     0.0033    0.0046    672.7709    1 ⋯
   regioncoefs[1][5]    0.2548    0.1268     0.0033    0.0050    609.4119    1 ⋯
   regioncoefs[1][6]    0.0852    0.1190     0.0031    0.0045    606.7495    1 ⋯
   regioncoefs[1][7]   -0.1090    0.1243     0.0032    0.0052    580.2901    1 ⋯
   regioncoefs[1][8]   -0.1379    0.1195     0.0031    0.0044    618.0759    1 ⋯
          ⋮               ⋮         ⋮         ⋮          ⋮          ⋮          ⋱
                                                   1 column and 922 rows omitted
Quantiles
          parameters      2.5%     25.0%     50.0%     75.0%     97.5% 
              Symbol   Float64   Float64   Float64   Float64   Float64 
             lawrate    1.2860    2.5526    3.5952    4.8667    7.5789
         meanlawcoef   -0.0600    0.0308    0.0769    0.1286    0.2305
      nationcoefs[1]   -1.3038   -0.4206    0.0530    0.4883    1.3601
      nationcoefs[2]   -1.2417   -0.3278    0.0893    0.5544    1.4339
      nationcoefs[3]   -1.1549   -0.3703    0.0693    0.5351    1.3838
      nationcoefs[4]   -1.5496   -0.6589   -0.1902    0.2819    1.1394
      nationcoefs[5]   -1.1076   -0.1814    0.2407    0.6636    1.5180
      nationcoefs[6]   -1.3414   -0.4145    0.0626    0.5124    1.3563
      nationcoefs[7]   -1.3626   -0.5561   -0.1082    0.3487    1.2005
      nationcoefs[8]   -1.2456   -0.4899   -0.0769    0.3145    1.2251
      nationcoefs[9]   -1.3541   -0.5023   -0.0813    0.3565    1.1455
     nationcoefs[10]   -1.4624   -0.6175   -0.1640    0.3601    1.1430
     nationcoefs[11]   -1.5876   -0.7335   -0.2238    0.2244    1.1076
     nationcoefs[12]   -1.2614   -0.2775    0.1811    0.6277    1.5597
     nationcoefs[13]   -1.2869   -0.5087   -0.0510    0.4281    1.2845
   regioncoefs[1][1]   -0.2448   -0.0539    0.0454    0.1473    0.3402
   regioncoefs[1][2]   -0.2557   -0.0850    0.0013    0.1010    0.2735
   regioncoefs[1][3]   -0.0967    0.0985    0.1816    0.2700    0.4608
   regioncoefs[1][4]   -0.5491   -0.3894   -0.3052   -0.2129   -0.0416
   regioncoefs[1][5]    0.0039    0.1718    0.2549    0.3322    0.5198
   regioncoefs[1][6]   -0.1424    0.0043    0.0845    0.1593    0.3240
   regioncoefs[1][7]   -0.3363   -0.1922   -0.1132   -0.0275    0.1429
   regioncoefs[1][8]   -0.3725   -0.2160   -0.1408   -0.0616    0.1019
          ⋮               ⋮         ⋮         ⋮         ⋮         ⋮
                                                        922 rows omitted

Having sampled the model, we can then compute summary graphs of the results. We will show the posterior density for the coefficient of the magnitude of the law effect for each state separately.

Also we will plot the actual log(homicide rate) together with the state specific counterfactual estimates.

lawco = group(s,"statelawcoef")

statenames = Dict()
for (st,stusab) in Iterators.zip(lawdates.STATE,lawdates.STUSAB)
    statenames[st] = stusab
    end

function plotlawts(s,lawdates,modeljoined)
let pl = []
    lawco = group(s,"statelawcoef")

    for i in @select(@subset(lawdates,:year .< 2022),:STATE).STATE
        den = density(s[:,Symbol("meanlawcoef"),:] .+ lawco[:,Symbol("statelawcoef[$i]"),:], title = "State $i = $(statenames[i])",
            legend=false,xlim=(-log(2),log(2)))
        plot!([(0.0,0.0),(0.0,5.0)], color="red",ylim=(0.0,5.0))
        push!(pl,den)
    end
    println("State law coefficient values")
    display(plot(pl...; size = (1000,1000)))

    display(density(s[:,:lawrate,:], title= "Law effect onset rate (1/yr)"))

    modeljoined.logdrate = log.(modeljoined.crudedeathrate)

    regions = Dict()
    for r in eachrow(stategroupdf)
        regions[r.STATE] = (group=r.stgroup,code=r.STUSAB)
    end
    pl = []
    samps = sample(1:500,10)

    for st in unique(modeljoined.STATE)
        sub = @subset(modeljoined, :STATE .== st)
        region = regions[st].group
        p = plot(sub.year,sub.logdrate,linewidth=3,title="$(st) = $(regions[st].code)",ylim=(-0.5,2.75))
        push!(pl,p)
        for samp in samps
            statelawcoef = s[samp,Symbol("statelawcoef[$st]"),1]
            statecoefs = [s[samp,Symbol("statecoefs[$st][$i]"),1] for i in 1:length(centers)]
            statebase = s[samp,Symbol("statebase[$st]"),1]
            regioncoefs = [s[samp,Symbol("regioncoefs[$region][$i]"),1] for i in 1:length(centers)]        
            
            lawrate = s[samp,:lawrate,1]
            startlaw = lawdates[lawdates.STATE .== st,:].year[1]
            startlaw = ismissing(startlaw) ? 3000 : startlaw
            years = 1979:2020
            pred = [statebase + 
                timeser(yr,regioncoefs .+ (statecoefpert .* statecoefs),centers,width) for yr in years]
            plot!(years,pred; color="orange",alpha=0.5)
            if startlaw < 3000
                plot!([(startlaw,-10.0),(startlaw,10.0)],color="red")
            end
            regpred = [statebase + 
                timeser(yr,regioncoefs ,centers,width) for yr in years]

        end
    end
    println("Each state shown with its locally estimated counterfactual (orange), actual (dark blue), and date of CC law if any (red vertical)")
    display(plot(pl...; size =(2000,3000), legend=false))
end

density(s[:,:meanlawcoef,:],title="Mean law coefficient")
end

plotlawts(s,lawdates,modeljoined)
State law coefficient values

Each state shown with its locally estimated counterfactual (orange), actual (dark blue), and date of CC law if any (red vertical)

Shall-issue vs permitless

One plausible explanation for the relative lack of clear measurable effect from permitless carry laws is that permitless actually may have had very little effect on how many people carry firearms in public. Many of these states were shall-issue and many people who wanted to carry may have had CCW permits issued before the permitless law passed. Therefore the change in number of people carrying may have been minimal.

Using the date on which states converted to shall-issue permits, with a similar analysis, we can determine whether more of an effect was visible after that legal change. Some states converted from no-issue to shall issue, while others converted from may-issue to shall-issue.

# dates collected from https://en.wikipedia.org/wiki/History_of_concealed_carry_in_the_United_States
shallissdates = CSV.read("data/ShallIssueDates.csv",DataFrame)

shallissue = leftjoin(fipscodes,shallissdates; on = :STUSAB)

silawdates = @chain leftjoin(DataFrame(STATE=1:55),shallissue; on=:STATE) begin
    @subset(:STATE .< 60)
    @rtransform(:year = ismissing(:ShallIssueDate) ? 3000 : :ShallIssueDate)
    @orderby(:STATE)
end

modl2 = guns(modeljoined.StateCode,maximum(modeljoined.StateCode),modeljoined.stgroup,maximum(modeljoined.stgroup),
        centers, width, modeljoined.year,log.(modeljoined.crudedeathrate),silawdates.year,statecoefpert)



savedfile = "./saved/shallisssamples.dat"
global sisam = []
if stat(savedfile).mtime > stat("./model.jl").mtime
    global sisam = deserialize(savedfile)
else
    global sisam = sample(modl2,NUTS(500,0.8),MCMCThreads(),500,3)
    serialize(savedfile,sisam)
end
Chains MCMC chain (500×957×3 Array{Float64, 3}):
Iterations        = 1:1:500
Number of chains  = 3
Samples per chain = 500
parameters        = lawrate, meanlawcoef, nationcoefs[1], nationcoefs[2], nationcoefs[3], nationcoefs[4], nationcoefs[5], nationcoefs[6], nationcoefs[7], nationcoefs[8], nationcoefs[9], nationcoefs[10], nationcoefs[11], nationcoefs[12], nationcoefs[13], regioncoefs[1][1], regioncoefs[1][2], regioncoefs[1][3], regioncoefs[1][4], regioncoefs[1][5], regioncoefs[1][6], regioncoefs[1][7], regioncoefs[1][8], regioncoefs[1][9], regioncoefs[1][10], regioncoefs[1][11], regioncoefs[1][12], regioncoefs[1][13], regioncoefs[2][1], regioncoefs[2][2], regioncoefs[2][3], regioncoefs[2][4], regioncoefs[2][5], regioncoefs[2][6], regioncoefs[2][7], regioncoefs[2][8], regioncoefs[2][9], regioncoefs[2][10], regioncoefs[2][11], regioncoefs[2][12], regioncoefs[2][13], regioncoefs[3][1], regioncoefs[3][2], regioncoefs[3][3], regioncoefs[3][4], regioncoefs[3][5], regioncoefs[3][6], regioncoefs[3][7], regioncoefs[3][8], regioncoefs[3][9], regioncoefs[3][10], regioncoefs[3][11], regioncoefs[3][12], regioncoefs[3][13], regioncoefs[4][1], regioncoefs[4][2], regioncoefs[4][3], regioncoefs[4][4], regioncoefs[4][5], regioncoefs[4][6], regioncoefs[4][7], regioncoefs[4][8], regioncoefs[4][9], regioncoefs[4][10], regioncoefs[4][11], regioncoefs[4][12], regioncoefs[4][13], regioncoefs[5][1], regioncoefs[5][2], regioncoefs[5][3], regioncoefs[5][4], regioncoefs[5][5], regioncoefs[5][6], regioncoefs[5][7], regioncoefs[5][8], regioncoefs[5][9], regioncoefs[5][10], regioncoefs[5][11], regioncoefs[5][12], regioncoefs[5][13], regioncoefs[6][1], regioncoefs[6][2], regioncoefs[6][3], regioncoefs[6][4], regioncoefs[6][5], regioncoefs[6][6], regioncoefs[6][7], regioncoefs[6][8], regioncoefs[6][9], regioncoefs[6][10], regioncoefs[6][11], regioncoefs[6][12], regioncoefs[6][13], regioncoefs[7][1], regioncoefs[7][2], regioncoefs[7][3], regioncoefs[7][4], regioncoefs[7][5], regioncoefs[7][6], regioncoefs[7][7], regioncoefs[7][8], regioncoefs[7][9], regioncoefs[7][10], regioncoefs[7][11], regioncoefs[7][12], regioncoefs[7][13], regioncoefs[8][1], regioncoefs[8][2], regioncoefs[8][3], regioncoefs[8][4], regioncoefs[8][5], regioncoefs[8][6], regioncoefs[8][7], regioncoefs[8][8], regioncoefs[8][9], regioncoefs[8][10], regioncoefs[8][11], regioncoefs[8][12], regioncoefs[8][13], scale, statebase[1], statebase[2], statebase[3], statebase[4], statebase[5], statebase[6], statebase[7], statebase[8], statebase[9], statebase[10], statebase[11], statebase[12], statebase[13], statebase[14], statebase[15], statebase[16], statebase[17], statebase[18], statebase[19], statebase[20], statebase[21], statebase[22], statebase[23], statebase[24], statebase[25], statebase[26], statebase[27], statebase[28], statebase[29], statebase[30], statebase[31], statebase[32], statebase[33], statebase[34], statebase[35], statebase[36], statebase[37], statebase[38], statebase[39], statebase[40], statebase[41], statebase[42], statebase[43], statebase[44], statebase[45], statebase[46], statebase[47], statebase[48], statebase[49], statebase[50], statebase[51], statebase[52], statebase[53], statebase[54], statebase[55], statecoefs[1][1], statecoefs[1][2], statecoefs[1][3], statecoefs[1][4], statecoefs[1][5], statecoefs[1][6], statecoefs[1][7], statecoefs[1][8], statecoefs[1][9], statecoefs[1][10], statecoefs[1][11], statecoefs[1][12], statecoefs[1][13], statecoefs[2][1], statecoefs[2][2], statecoefs[2][3], statecoefs[2][4], statecoefs[2][5], statecoefs[2][6], statecoefs[2][7], statecoefs[2][8], statecoefs[2][9], statecoefs[2][10], statecoefs[2][11], statecoefs[2][12], statecoefs[2][13], statecoefs[3][1], statecoefs[3][2], statecoefs[3][3], statecoefs[3][4], statecoefs[3][5], statecoefs[3][6], statecoefs[3][7], statecoefs[3][8], statecoefs[3][9], statecoefs[3][10], statecoefs[3][11], statecoefs[3][12], statecoefs[3][13], statecoefs[4][1], statecoefs[4][2], statecoefs[4][3], statecoefs[4][4], statecoefs[4][5], statecoefs[4][6], statecoefs[4][7], statecoefs[4][8], statecoefs[4][9], statecoefs[4][10], statecoefs[4][11], statecoefs[4][12], statecoefs[4][13], statecoefs[5][1], statecoefs[5][2], statecoefs[5][3], statecoefs[5][4], statecoefs[5][5], statecoefs[5][6], statecoefs[5][7], statecoefs[5][8], statecoefs[5][9], statecoefs[5][10], statecoefs[5][11], statecoefs[5][12], statecoefs[5][13], statecoefs[6][1], statecoefs[6][2], statecoefs[6][3], statecoefs[6][4], statecoefs[6][5], statecoefs[6][6], statecoefs[6][7], statecoefs[6][8], statecoefs[6][9], statecoefs[6][10], statecoefs[6][11], statecoefs[6][12], statecoefs[6][13], statecoefs[7][1], statecoefs[7][2], statecoefs[7][3], statecoefs[7][4], statecoefs[7][5], statecoefs[7][6], statecoefs[7][7], statecoefs[7][8], statecoefs[7][9], statecoefs[7][10], statecoefs[7][11], statecoefs[7][12], statecoefs[7][13], statecoefs[8][1], statecoefs[8][2], statecoefs[8][3], statecoefs[8][4], statecoefs[8][5], statecoefs[8][6], statecoefs[8][7], statecoefs[8][8], statecoefs[8][9], statecoefs[8][10], statecoefs[8][11], statecoefs[8][12], statecoefs[8][13], statecoefs[9][1], statecoefs[9][2], statecoefs[9][3], statecoefs[9][4], statecoefs[9][5], statecoefs[9][6], statecoefs[9][7], statecoefs[9][8], statecoefs[9][9], statecoefs[9][10], statecoefs[9][11], statecoefs[9][12], statecoefs[9][13], statecoefs[10][1], statecoefs[10][2], statecoefs[10][3], statecoefs[10][4], statecoefs[10][5], statecoefs[10][6], statecoefs[10][7], statecoefs[10][8], statecoefs[10][9], statecoefs[10][10], statecoefs[10][11], statecoefs[10][12], statecoefs[10][13], statecoefs[11][1], statecoefs[11][2], statecoefs[11][3], statecoefs[11][4], statecoefs[11][5], statecoefs[11][6], statecoefs[11][7], statecoefs[11][8], statecoefs[11][9], statecoefs[11][10], statecoefs[11][11], statecoefs[11][12], statecoefs[11][13], statecoefs[12][1], statecoefs[12][2], statecoefs[12][3], statecoefs[12][4], statecoefs[12][5], statecoefs[12][6], statecoefs[12][7], statecoefs[12][8], statecoefs[12][9], statecoefs[12][10], statecoefs[12][11], statecoefs[12][12], statecoefs[12][13], statecoefs[13][1], statecoefs[13][2], statecoefs[13][3], statecoefs[13][4], statecoefs[13][5], statecoefs[13][6], statecoefs[13][7], statecoefs[13][8], statecoefs[13][9], statecoefs[13][10], statecoefs[13][11], statecoefs[13][12], statecoefs[13][13], statecoefs[14][1], statecoefs[14][2], statecoefs[14][3], statecoefs[14][4], statecoefs[14][5], statecoefs[14][6], statecoefs[14][7], statecoefs[14][8], statecoefs[14][9], statecoefs[14][10], statecoefs[14][11], statecoefs[14][12], statecoefs[14][13], statecoefs[15][1], statecoefs[15][2], statecoefs[15][3], statecoefs[15][4], statecoefs[15][5], statecoefs[15][6], statecoefs[15][7], statecoefs[15][8], statecoefs[15][9], statecoefs[15][10], statecoefs[15][11], statecoefs[15][12], statecoefs[15][13], statecoefs[16][1], statecoefs[16][2], statecoefs[16][3], statecoefs[16][4], statecoefs[16][5], statecoefs[16][6], statecoefs[16][7], statecoefs[16][8], statecoefs[16][9], statecoefs[16][10], statecoefs[16][11], statecoefs[16][12], statecoefs[16][13], statecoefs[17][1], statecoefs[17][2], statecoefs[17][3], statecoefs[17][4], statecoefs[17][5], statecoefs[17][6], statecoefs[17][7], statecoefs[17][8], statecoefs[17][9], statecoefs[17][10], statecoefs[17][11], statecoefs[17][12], statecoefs[17][13], statecoefs[18][1], statecoefs[18][2], statecoefs[18][3], statecoefs[18][4], statecoefs[18][5], statecoefs[18][6], statecoefs[18][7], statecoefs[18][8], statecoefs[18][9], statecoefs[18][10], statecoefs[18][11], statecoefs[18][12], statecoefs[18][13], statecoefs[19][1], statecoefs[19][2], statecoefs[19][3], statecoefs[19][4], statecoefs[19][5], statecoefs[19][6], statecoefs[19][7], statecoefs[19][8], statecoefs[19][9], statecoefs[19][10], statecoefs[19][11], statecoefs[19][12], statecoefs[19][13], statecoefs[20][1], statecoefs[20][2], statecoefs[20][3], statecoefs[20][4], statecoefs[20][5], statecoefs[20][6], statecoefs[20][7], statecoefs[20][8], statecoefs[20][9], statecoefs[20][10], statecoefs[20][11], statecoefs[20][12], statecoefs[20][13], statecoefs[21][1], statecoefs[21][2], statecoefs[21][3], statecoefs[21][4], statecoefs[21][5], statecoefs[21][6], statecoefs[21][7], statecoefs[21][8], statecoefs[21][9], statecoefs[21][10], statecoefs[21][11], statecoefs[21][12], statecoefs[21][13], statecoefs[22][1], statecoefs[22][2], statecoefs[22][3], statecoefs[22][4], statecoefs[22][5], statecoefs[22][6], statecoefs[22][7], statecoefs[22][8], statecoefs[22][9], statecoefs[22][10], statecoefs[22][11], statecoefs[22][12], statecoefs[22][13], statecoefs[23][1], statecoefs[23][2], statecoefs[23][3], statecoefs[23][4], statecoefs[23][5], statecoefs[23][6], statecoefs[23][7], statecoefs[23][8], statecoefs[23][9], statecoefs[23][10], statecoefs[23][11], statecoefs[23][12], statecoefs[23][13], statecoefs[24][1], statecoefs[24][2], statecoefs[24][3], statecoefs[24][4], statecoefs[24][5], statecoefs[24][6], statecoefs[24][7], statecoefs[24][8], statecoefs[24][9], statecoefs[24][10], statecoefs[24][11], statecoefs[24][12], statecoefs[24][13], statecoefs[25][1], statecoefs[25][2], statecoefs[25][3], statecoefs[25][4], statecoefs[25][5], statecoefs[25][6], statecoefs[25][7], statecoefs[25][8], statecoefs[25][9], statecoefs[25][10], statecoefs[25][11], statecoefs[25][12], statecoefs[25][13], statecoefs[26][1], statecoefs[26][2], statecoefs[26][3], statecoefs[26][4], statecoefs[26][5], statecoefs[26][6], statecoefs[26][7], statecoefs[26][8], statecoefs[26][9], statecoefs[26][10], statecoefs[26][11], statecoefs[26][12], statecoefs[26][13], statecoefs[27][1], statecoefs[27][2], statecoefs[27][3], statecoefs[27][4], statecoefs[27][5], statecoefs[27][6], statecoefs[27][7], statecoefs[27][8], statecoefs[27][9], statecoefs[27][10], statecoefs[27][11], statecoefs[27][12], statecoefs[27][13], statecoefs[28][1], statecoefs[28][2], statecoefs[28][3], statecoefs[28][4], statecoefs[28][5], statecoefs[28][6], statecoefs[28][7], statecoefs[28][8], statecoefs[28][9], statecoefs[28][10], statecoefs[28][11], statecoefs[28][12], statecoefs[28][13], statecoefs[29][1], statecoefs[29][2], statecoefs[29][3], statecoefs[29][4], statecoefs[29][5], statecoefs[29][6], statecoefs[29][7], statecoefs[29][8], statecoefs[29][9], statecoefs[29][10], statecoefs[29][11], statecoefs[29][12], statecoefs[29][13], statecoefs[30][1], statecoefs[30][2], statecoefs[30][3], statecoefs[30][4], statecoefs[30][5], statecoefs[30][6], statecoefs[30][7], statecoefs[30][8], statecoefs[30][9], statecoefs[30][10], statecoefs[30][11], statecoefs[30][12], statecoefs[30][13], statecoefs[31][1], statecoefs[31][2], statecoefs[31][3], statecoefs[31][4], statecoefs[31][5], statecoefs[31][6], statecoefs[31][7], statecoefs[31][8], statecoefs[31][9], statecoefs[31][10], statecoefs[31][11], statecoefs[31][12], statecoefs[31][13], statecoefs[32][1], statecoefs[32][2], statecoefs[32][3], statecoefs[32][4], statecoefs[32][5], statecoefs[32][6], statecoefs[32][7], statecoefs[32][8], statecoefs[32][9], statecoefs[32][10], statecoefs[32][11], statecoefs[32][12], statecoefs[32][13], statecoefs[33][1], statecoefs[33][2], statecoefs[33][3], statecoefs[33][4], statecoefs[33][5], statecoefs[33][6], statecoefs[33][7], statecoefs[33][8], statecoefs[33][9], statecoefs[33][10], statecoefs[33][11], statecoefs[33][12], statecoefs[33][13], statecoefs[34][1], statecoefs[34][2], statecoefs[34][3], statecoefs[34][4], statecoefs[34][5], statecoefs[34][6], statecoefs[34][7], statecoefs[34][8], statecoefs[34][9], statecoefs[34][10], statecoefs[34][11], statecoefs[34][12], statecoefs[34][13], statecoefs[35][1], statecoefs[35][2], statecoefs[35][3], statecoefs[35][4], statecoefs[35][5], statecoefs[35][6], statecoefs[35][7], statecoefs[35][8], statecoefs[35][9], statecoefs[35][10], statecoefs[35][11], statecoefs[35][12], statecoefs[35][13], statecoefs[36][1], statecoefs[36][2], statecoefs[36][3], statecoefs[36][4], statecoefs[36][5], statecoefs[36][6], statecoefs[36][7], statecoefs[36][8], statecoefs[36][9], statecoefs[36][10], statecoefs[36][11], statecoefs[36][12], statecoefs[36][13], statecoefs[37][1], statecoefs[37][2], statecoefs[37][3], statecoefs[37][4], statecoefs[37][5], statecoefs[37][6], statecoefs[37][7], statecoefs[37][8], statecoefs[37][9], statecoefs[37][10], statecoefs[37][11], statecoefs[37][12], statecoefs[37][13], statecoefs[38][1], statecoefs[38][2], statecoefs[38][3], statecoefs[38][4], statecoefs[38][5], statecoefs[38][6], statecoefs[38][7], statecoefs[38][8], statecoefs[38][9], statecoefs[38][10], statecoefs[38][11], statecoefs[38][12], statecoefs[38][13], statecoefs[39][1], statecoefs[39][2], statecoefs[39][3], statecoefs[39][4], statecoefs[39][5], statecoefs[39][6], statecoefs[39][7], statecoefs[39][8], statecoefs[39][9], statecoefs[39][10], statecoefs[39][11], statecoefs[39][12], statecoefs[39][13], statecoefs[40][1], statecoefs[40][2], statecoefs[40][3], statecoefs[40][4], statecoefs[40][5], statecoefs[40][6], statecoefs[40][7], statecoefs[40][8], statecoefs[40][9], statecoefs[40][10], statecoefs[40][11], statecoefs[40][12], statecoefs[40][13], statecoefs[41][1], statecoefs[41][2], statecoefs[41][3], statecoefs[41][4], statecoefs[41][5], statecoefs[41][6], statecoefs[41][7], statecoefs[41][8], statecoefs[41][9], statecoefs[41][10], statecoefs[41][11], statecoefs[41][12], statecoefs[41][13], statecoefs[42][1], statecoefs[42][2], statecoefs[42][3], statecoefs[42][4], statecoefs[42][5], statecoefs[42][6], statecoefs[42][7], statecoefs[42][8], statecoefs[42][9], statecoefs[42][10], statecoefs[42][11], statecoefs[42][12], statecoefs[42][13], statecoefs[43][1], statecoefs[43][2], statecoefs[43][3], statecoefs[43][4], statecoefs[43][5], statecoefs[43][6], statecoefs[43][7], statecoefs[43][8], statecoefs[43][9], statecoefs[43][10], statecoefs[43][11], statecoefs[43][12], statecoefs[43][13], statecoefs[44][1], statecoefs[44][2], statecoefs[44][3], statecoefs[44][4], statecoefs[44][5], statecoefs[44][6], statecoefs[44][7], statecoefs[44][8], statecoefs[44][9], statecoefs[44][10], statecoefs[44][11], statecoefs[44][12], statecoefs[44][13], statecoefs[45][1], statecoefs[45][2], statecoefs[45][3], statecoefs[45][4], statecoefs[45][5], statecoefs[45][6], statecoefs[45][7], statecoefs[45][8], statecoefs[45][9], statecoefs[45][10], statecoefs[45][11], statecoefs[45][12], statecoefs[45][13], statecoefs[46][1], statecoefs[46][2], statecoefs[46][3], statecoefs[46][4], statecoefs[46][5], statecoefs[46][6], statecoefs[46][7], statecoefs[46][8], statecoefs[46][9], statecoefs[46][10], statecoefs[46][11], statecoefs[46][12], statecoefs[46][13], statecoefs[47][1], statecoefs[47][2], statecoefs[47][3], statecoefs[47][4], statecoefs[47][5], statecoefs[47][6], statecoefs[47][7], statecoefs[47][8], statecoefs[47][9], statecoefs[47][10], statecoefs[47][11], statecoefs[47][12], statecoefs[47][13], statecoefs[48][1], statecoefs[48][2], statecoefs[48][3], statecoefs[48][4], statecoefs[48][5], statecoefs[48][6], statecoefs[48][7], statecoefs[48][8], statecoefs[48][9], statecoefs[48][10], statecoefs[48][11], statecoefs[48][12], statecoefs[48][13], statecoefs[49][1], statecoefs[49][2], statecoefs[49][3], statecoefs[49][4], statecoefs[49][5], statecoefs[49][6], statecoefs[49][7], statecoefs[49][8], statecoefs[49][9], statecoefs[49][10], statecoefs[49][11], statecoefs[49][12], statecoefs[49][13], statecoefs[50][1], statecoefs[50][2], statecoefs[50][3], statecoefs[50][4], statecoefs[50][5], statecoefs[50][6], statecoefs[50][7], statecoefs[50][8], statecoefs[50][9], statecoefs[50][10], statecoefs[50][11], statecoefs[50][12], statecoefs[50][13], statecoefs[51][1], statecoefs[51][2], statecoefs[51][3], statecoefs[51][4], statecoefs[51][5], statecoefs[51][6], statecoefs[51][7], statecoefs[51][8], statecoefs[51][9], statecoefs[51][10], statecoefs[51][11], statecoefs[51][12], statecoefs[51][13], statecoefs[52][1], statecoefs[52][2], statecoefs[52][3], statecoefs[52][4], statecoefs[52][5], statecoefs[52][6], statecoefs[52][7], statecoefs[52][8], statecoefs[52][9], statecoefs[52][10], statecoefs[52][11], statecoefs[52][12], statecoefs[52][13], statecoefs[53][1], statecoefs[53][2], statecoefs[53][3], statecoefs[53][4], statecoefs[53][5], statecoefs[53][6], statecoefs[53][7], statecoefs[53][8], statecoefs[53][9], statecoefs[53][10], statecoefs[53][11], statecoefs[53][12], statecoefs[53][13], statecoefs[54][1], statecoefs[54][2], statecoefs[54][3], statecoefs[54][4], statecoefs[54][5], statecoefs[54][6], statecoefs[54][7], statecoefs[54][8], statecoefs[54][9], statecoefs[54][10], statecoefs[54][11], statecoefs[54][12], statecoefs[54][13], statecoefs[55][1], statecoefs[55][2], statecoefs[55][3], statecoefs[55][4], statecoefs[55][5], statecoefs[55][6], statecoefs[55][7], statecoefs[55][8], statecoefs[55][9], statecoefs[55][10], statecoefs[55][11], statecoefs[55][12], statecoefs[55][13], statelawcoef[1], statelawcoef[2], statelawcoef[3], statelawcoef[4], statelawcoef[5], statelawcoef[6], statelawcoef[7], statelawcoef[8], statelawcoef[9], statelawcoef[10], statelawcoef[11], statelawcoef[12], statelawcoef[13], statelawcoef[14], statelawcoef[15], statelawcoef[16], statelawcoef[17], statelawcoef[18], statelawcoef[19], statelawcoef[20], statelawcoef[21], statelawcoef[22], statelawcoef[23], statelawcoef[24], statelawcoef[25], statelawcoef[26], statelawcoef[27], statelawcoef[28], statelawcoef[29], statelawcoef[30], statelawcoef[31], statelawcoef[32], statelawcoef[33], statelawcoef[34], statelawcoef[35], statelawcoef[36], statelawcoef[37], statelawcoef[38], statelawcoef[39], statelawcoef[40], statelawcoef[41], statelawcoef[42], statelawcoef[43], statelawcoef[44], statelawcoef[45], statelawcoef[46], statelawcoef[47], statelawcoef[48], statelawcoef[49], statelawcoef[50], statelawcoef[51], statelawcoef[52], statelawcoef[53], statelawcoef[54], statelawcoef[55]
internals         = acceptance_rate, hamiltonian_energy, hamiltonian_energy_error, is_accept, log_density, lp, max_hamiltonian_energy_error, n_steps, nom_step_size, numerical_error, step_size, tree_depth
Summary Statistics
          parameters      mean       std   naive_se      mcse         ess                  Symbol   Float64   Float64    Float64   Float64     Float64   Fl ⋯
             lawrate    2.8087    1.7432     0.0450    0.0482   1611.3276    0 ⋯
         meanlawcoef    0.0115    0.0430     0.0011    0.0013   1171.1740    1 ⋯
      nationcoefs[1]    0.0454    0.6693     0.0173    0.0119   4509.6864    0 ⋯
      nationcoefs[2]    0.1063    0.6770     0.0175    0.0104   3474.9550    0 ⋯
      nationcoefs[3]    0.0445    0.6676     0.0172    0.0083   4239.3948    0 ⋯
      nationcoefs[4]   -0.1756    0.6736     0.0174    0.0117   5174.1939    0 ⋯
      nationcoefs[5]    0.2191    0.6338     0.0164    0.0125   3560.7361    0 ⋯
      nationcoefs[6]    0.0455    0.6687     0.0173    0.0119   3616.7562    0 ⋯
      nationcoefs[7]   -0.0847    0.6525     0.0168    0.0090   4325.9386    0 ⋯
      nationcoefs[8]   -0.0766    0.6925     0.0179    0.0147   3488.7226    0 ⋯
      nationcoefs[9]   -0.0789    0.6584     0.0170    0.0103   4879.4022    0 ⋯
     nationcoefs[10]   -0.1012    0.6951     0.0179    0.0133   3771.9762    0 ⋯
     nationcoefs[11]   -0.2371    0.6727     0.0174    0.0121   3800.0082    0 ⋯
     nationcoefs[12]    0.1902    0.7024     0.0181    0.0126   3883.0790    0 ⋯
     nationcoefs[13]   -0.0589    0.6733     0.0174    0.0121   4791.5516    0 ⋯
   regioncoefs[1][1]    0.0455    0.1455     0.0038    0.0053    915.0360    0 ⋯
   regioncoefs[1][2]    0.0056    0.1391     0.0036    0.0049    887.1261    1 ⋯
   regioncoefs[1][3]    0.1963    0.1374     0.0035    0.0053    739.1493    1 ⋯
   regioncoefs[1][4]   -0.3116    0.1279     0.0033    0.0047    770.5142    1 ⋯
   regioncoefs[1][5]    0.2675    0.1255     0.0032    0.0049    650.7455    1 ⋯
   regioncoefs[1][6]    0.0857    0.1176     0.0030    0.0053    566.6723    1 ⋯
   regioncoefs[1][7]   -0.1386    0.1237     0.0032    0.0049    689.3163    1 ⋯
   regioncoefs[1][8]   -0.1362    0.1167     0.0030    0.0041    773.5224    1 ⋯
          ⋮               ⋮         ⋮         ⋮          ⋮          ⋮          ⋱
                                                   1 column and 922 rows omitted
Quantiles
          parameters      2.5%     25.0%     50.0%     75.0%     97.5% 
              Symbol   Float64   Float64   Float64   Float64   Float64 
             lawrate    0.5643    1.4218    2.4587    3.7840    6.9214
         meanlawcoef   -0.0757   -0.0165    0.0119    0.0418    0.0912
      nationcoefs[1]   -1.2758   -0.3997    0.0410    0.5035    1.3141
      nationcoefs[2]   -1.1713   -0.3666    0.0981    0.5606    1.3667
      nationcoefs[3]   -1.2168   -0.3970    0.0395    0.4744    1.4215
      nationcoefs[4]   -1.5332   -0.6247   -0.1857    0.2696    1.1986
      nationcoefs[5]   -1.0214   -0.2156    0.2235    0.6298    1.4570
      nationcoefs[6]   -1.2468   -0.3962    0.0414    0.5116    1.2780
      nationcoefs[7]   -1.4074   -0.5196   -0.0850    0.3639    1.1992
      nationcoefs[8]   -1.3601   -0.5607   -0.0873    0.3808    1.2965
      nationcoefs[9]   -1.3918   -0.5245   -0.0714    0.3790    1.2148
     nationcoefs[10]   -1.4440   -0.5720   -0.0998    0.3528    1.2762
     nationcoefs[11]   -1.5324   -0.6804   -0.2417    0.2420    1.0584
     nationcoefs[12]   -1.2364   -0.2759    0.1701    0.6653    1.5755
     nationcoefs[13]   -1.3574   -0.4996   -0.0728    0.4052    1.2114
   regioncoefs[1][1]   -0.2364   -0.0540    0.0442    0.1465    0.3246
   regioncoefs[1][2]   -0.2565   -0.0905    0.0007    0.1011    0.2876
   regioncoefs[1][3]   -0.0709    0.1004    0.1989    0.2941    0.4571
   regioncoefs[1][4]   -0.5590   -0.3974   -0.3110   -0.2251   -0.0640
   regioncoefs[1][5]    0.0114    0.1853    0.2713    0.3527    0.5062
   regioncoefs[1][6]   -0.1377    0.0041    0.0868    0.1655    0.3144
   regioncoefs[1][7]   -0.3856   -0.2219   -0.1316   -0.0539    0.0937
   regioncoefs[1][8]   -0.3768   -0.2138   -0.1338   -0.0588    0.0854
          ⋮               ⋮         ⋮         ⋮         ⋮         ⋮
                                                        922 rows omitted

Shall Issue coefficients

plotlawts(sisam, silawdates,modeljoined)
State law coefficient values

Each state shown with its locally estimated counterfactual (orange), actual (dark blue), and date of CC law if any (red vertical)

The Take Home

Permitless/Constitutional Carry laws

Many states that have passed constitutional carry laws have done so recently enough that there is no data on homicides available from CDC Wonder yet.

For those which passed the law long enough ago to have some post-law data, still many of them were in the last few years leaving only a few years of post-law data. The last few years is a time period where homicides have increased nearly nationwide and it is challenging to estimate the effect of a law when it is imposed on top of a nonlinearly changing trend. Estimates of a law effect created by comparing the actual data to counterfactuals estimated as small perturbations to the regional trend lead to estimates of the average law coefficient that has uncertain sign, with a most likely value of about 0.05 or so, meaning that gun homicides may increase by a factor of around 1.05, however the ability to resolve this number is so poor that the number could be anything from about -0.1 to +0.25 (multiplying the crime rate by anywhere from 0.9 to 1.28.

Any kind of convincing evidence for a consistent average net positive or negative effect of passing constitutional carry laws simply isn’t there. What’s more, we have decent bounds on the size of this effect for most states, it should be somewhere between perhaps -0.25 and 0.25 on the log scale, meaning approximately the rate of homicides would be multiplied by some number in the range 0.78 to 1.28.

Shall issue laws

Because many shall-issue laws were passed in the 1990’s there is much better evidence for their long term effect on crime. However, using the same methodology as above the average effect is essentially symmetrically distributed around 0.0 with a posterior credible range of about -0.1 to 0.1. The only reasonably strong evidence we have in this data for a real effect is that Texas may have reduced crime with a coefficient around -0.3 and perhaps Pennsylvania caused an increase around 0.2, with Wisconsin possibly around 0.2. The PA estimate does see the counterfactual diverge around the time of the law, but the Wisconsin counterfactual diverges 20 years before the law, suggesting that that effect is really an artifact of a poor counterfactual estimate.

Firearms Sales

Firearms sales are driven by multiple factors. One is the fear of “bans” which drove a lot of sales around the time of the Sandy Hook school shooting in Dec 2012. And in general sales have increased over the last decade including a sudden increase after the turmoil of 2020, with women and racial minorities making up a historically unprecedented fraction of new sales (close to 50%).

Firearms sales can plausibly be both a cause of firearms crime (when people purchase firearms to commit crime), a response to violence (when people purchase firearms for defense after periods of crime), and even in some cases a deterrent to crime (when criminals meet with greater defensive responses than before). It is hard to say which of these effects dominates, and in fact most likely all of these occur at different times and different places. One thing is clear however, and that is that it is entirely possible for gun ownership to increase while crime decreases, or for crime to increase while gun ownership per capita decreases. Those who somehow wish to draw a direct causal link in the US between more guns and more gun crime simply do not have an easy obvious convincing argument.

The evidence suggests that in the post NYSRPA v Bruen era, forcing CA and NY and others to shall-issue their permits will by itself have very little effect on overall gun crime. More likely if there is an increase it will be due to the turmoil undergoing the whole country at the moment, with high levels of inflation and the war in Ukraine driving food prices up and crime in general increasing over the last few years.