DINA

This package uses DataDeps.jl to download the US distributional national accounts (DINA) dataset from Gabriel Zucman's website. The data are downloaded in bulk (>1GB) and stored in .julia/datadeps/dina/.

The dataset is described in Piketty, T, E. Saez and G. Zucman: Distributional National Accounts: Methods and Estimates for the United States, Quarterly Journal of Economics, 2018, 133 (2): 553-609.

The variables are described in the codebook at Gabriel Zucman's website.

Getting the micro data for a year

using DINA, DataFrames

tbl = get_dina(1980)
df80 = DataFrame(tbl)

first(df80, 5)
5×157 DataFrame
Rowiddweghtdweghttaxufemaleageprimagesecageoldexmoldexfoldmarriedsecondxkidspopfilerfiincfnincfaincflincfkincptincplincpkincdiincprincpeincpoinchwealfiwagfibusfirenfiintfidivfikgifnpspenincschcincscorincscorpincpartincpartpincrentincestincrylincothincintexmflempflmilflprlfkhoufkequfkfixfkbusfkpenfkdebplconplbelpkpenpkbekhwequhwfixhwhouhwbushwpenhwdebflwagflsupwaghealthwagpenflmil_sflmil_pfkhoumainfkhourentfkmorfknmofkprkproprestaxpropbustaxfkbus_pfkbus_sfkequ_sfkequ_crentalrentalhomerentalmortownerhomeownerhome_heterownermorthousingpartwsolepropscorwequitytaxbondtaxbond_rmmbondfundmunicurrencymiscwnonmorthwealnokghwfinhwnfahwfix_homohwequ_kghwhou_homoplpcoplocoplpbeplobeplbenplpblplninpkpbkpkninptnindicshinkindinccolexpgovinnpincprisupeninvpenpeinckpeinclprisupenprivateprisupgoveduccolexp2poinc2taxditaxditafditassalestaxcorptaxestatetaxgovcontribssuicontribothercontribssinc_oassinc_diuiincbendicabdicreddifoodisupdivetdiwcodicaotanfincothbenmedicaremedicaidotherkinpellvethealth
Int32Int32Int32Int8LabeledV…LabeledV…LabeledV…LabeledV…Int8Int8LabeledV…Int8Int8Int8Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Int32Int32Int32Int32Float64Float64Float64Float64Float64Float64Float64Int32Int32Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float32Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64
1-31710000017100000045-6445-6445-6465less00marr0118.39449e54.57699e51.69481e63.86985e51.30782e61.65815e64.55507e51.20264e61.33923e61.6776e61.78744e61.47903e69.25748e63.93949e5-291750.01342501064001148503817504.57699e534300.0-20400.0-37300.00.0-234050.00.011200130500-35650.028200.00.03.66393e50.020592.068179.87.6213e52.45488e532790.5214786.0-15551.0-10301.778823.0-1.34821e529642.73.15058e62.41204e62.005e63.33327e51.54359e6-1.8705e53.59649e56744.641341.467446.440.00.023767.444412.4-14895.8-655.28762679.818480.739613.232790.50.00.07.6213e51.34397e61.35527e6-11302.86.20192e56.49725e5-1.69075e51.82462e63.33327e50.00.02.51057e62.1419e62.1419e61.7436e50.00.095781.6-6672.968.61747e67.10621e62.33832e62.41204e63.36631e61.97546e6-9675.8-625.921.08323e5142.6081.08466e575942.14.53251e532381.01.20538e61.65863e61.06151e60.02.7772e5-22608.35397.9211678.11.34821e51.32026e64.67185e517684.24504.92896.0931.99133e51.39995e6557347.0120810.095755.725054.341121.12.68029e563766.75526.532855.282671.250.00.0182.9692.7772e50.00.00.00.00.00.00.00.00.00.00.00.00.00.0
2-31710000017100000145-6445-6445-6465less00marr1115.10151e51.28401e51.34735e639526.21.30782e61.31385e61.11202e51.20264e69.94551e51.33259e61.43073e61.12016e69.25748e664651.5-291750.01342501064001148503817501.28401e534300.0-20400.0-37300.00.0-234050.00.011200130500-35650.028200.00.037422.90.02103.2468179.87.6213e52.45488e532790.5214786.0-15551.0-7146.7878823.0-1.34821e529642.73.15058e62.41204e62.005e63.33327e51.54359e6-1.8705e530351.57071.461341.464371.570.00.023767.444412.4-14895.8-655.28762679.818480.739613.232790.50.00.07.6213e51.34397e61.35527e6-11302.86.20192e56.49725e5-1.69075e51.82462e63.33327e50.00.02.51057e62.1419e62.1419e61.7436e50.00.095781.6-6672.968.61747e67.10621e62.33832e62.41204e63.36631e61.97546e6-6529.96-616.8261.08323e5142.6081.08466e575942.11.08938e532381.01.20538e61.31432e67.88308e50.02.06243e5-18765.24008.65-3178.911.34821e51.32271e61.08023e51806.243739.15896.093148113.01.06167e64.93066e570138.255592.514545.729534.72.68029e563766.73503.632775.21728.4180.00.0182.9692.06243e50.00.00.00.00.00.00.00.00.00.00.00.00.00.0
3-21710000017100000045-6445-6445-6465less00marr0112.02375e61.46025e62.91813e65.16141e52.40199e62.90101e65.24128e52.37688e61.69033e62.87676e62.89687e61.70859e62.00869e7439474.045275.04818501590003346505635001.46025e66550.035550.020625.020625.0-10900.00.085300207300158400.030850.03.52261e54.31548e557127.627464.62.43673e51.48564e65.72349e562864.546524.2-9058.06-2900.9310887.9-29203.34094.586.15006e65.62362e67.28238e68.04892e53.34352e5-1.08425e5432924.0-1375.531341.460.057127.60.048271.71.95401e5-8402.77-655.2871.1512e567566.671630.052088.010776.515115.01.47052e65.95148e65.96279e6-11302.81.25962e61.3196e6-90449.07.18063e6529492.02.754e571037.06.558e63.26417e63.26417e65.08051e51.64112e62450.3207827.0-6672.962.04948e71.2108e78.08728e65.62362e66.01448e67.2224e6-2269.83-631.10514982.50.014982.510503.85.24375e54478.722.37727e62.90164e61.3398e60.03.5053e5-48188.96813.078027.1629203.32.36471e65.32155e520829.09602.11896.0932.51105e51.60854e61.49098e6673903.05.83506e590396.569457.74.64103e51.38361e55963.212900.933062.280.00.00.03.5053e50.00.00.00.00.00.00.00.00.00.00.00.00.00.0
4-21710000017100000145-6445-6445-6465less00marr1111.56655e61.00305e62.42111e631026.32.39008e62.40088e635907.12.36497e61.35991e62.38622e62.38589e61.36369e62.00869e730126.0-2575.04818501590003346505635001.00305e66550.03950.04375.04375.0-10900.00.085300207300158400.030850.03.52261e529375.30.01650.952.43673e51.47373e65.72349e562864.546524.2-9058.06-6007.1710887.9-29203.34094.586.15006e65.62362e67.28238e68.04892e53.34352e5-1.08425e523576.05799.351095.53395.690.00.048271.71.95401e5-8402.77-655.2871.14549e567566.671630.052088.010776.53206.211.47052e65.95148e65.96279e6-11302.81.25962e61.3196e6-90449.07.18063e6529492.02.754e571037.06.558e63.26417e63.26417e65.08051e51.64112e62450.3207827.0-6672.962.04948e71.2108e78.08728e65.62362e66.01448e67.2224e6-5415.49-591.67214982.50.014982.510503.836114.64478.722.36536e62.40147e61.0779e60.02.8201e5-40369.25481.28-9306.6429203.32.35929e626600.41417.828043.95896.093202195.01.28338e61.26365e6464470.04.02167e562303.554256.94.64103e51.38361e53260.092611.48648.6110.00.00.02.8201e50.00.00.00.00.00.00.00.00.00.00.00.00.00.0
5-11960000019600000020-4420-4420-4465less00marr021-1.9092e6-2.7447e61.32443e61.50049e51.17438e61.31059e61.41425e51.16916e61.08601e61.31126e61.30543e61.08901e66.01366e6135085.0-1.1806e6-18698359935071300835500-2.7447e62085.0-476600.0-142000.00.0-562000.00.0-187750-1184004755.0-1.56844e688025.71.42064e50.07984.30.09.66477e51.98642e50.09262.730.0-10209.41585.32-5814.22596.1853.99534e61.95176e60.00.066567.80.0133000.09064.291341.467446.440.00.00.00.00.00.056284.40.040808.10.00.00.09.66477e50.00.00.00.00.00.00.00.00.00.01.17057e61.37119e61.37119e61.08245e54.10098e50.062219.70.03.18889e66.01366e60.01.95176e64.94512e60.0-9593.97-615.4362176.94.600252181.51526.161.41981e5650.7421.16922e61.3112e6860800.00.02.25209e5-17547.64377.292195.165814.221.16181e61.4362e56856.843496.521792.19162547.01.02595e64.20461e56.394376.394370.032172.73.0195e541422.94101.482762.971338.510.00.05.902212.25216e56.349666.349660.00.00.00.00.00.00.00.00.00.00.00.0

Getting the decile-year panel for selected variables

using DINA
import CSV

inc = :peinc
wgt = :dweght

dbt_var = [:ownermort, :rentalmort, :nonmort, :hwdeb]
var = [[:fiinc, :fninc, :ptinc, inc, :poinc, :ownerhome, :rentalhome]; dbt_var]
byvar = inc # compute deciles of `:peinc`

df = dina_quantile_panel(var, byvar, 10)


first(df, 5)
5×16 DataFrame
Rowgroup_idagefiincfnincptincpeincpoincownerhomerentalhomeownermortrentalmortnonmorthwdebdweghtyearthree_groups
Int64LabeledV…Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Int64String
11065plus18165.815120.042636.543357.634265.031786.025523.0-2184.5-1250.51-6364.02-9799.042.24867e111962top 10
2265plus274.744263.8072166.422154.992737.492093.36593.084-55.0185-41.5938-106.612-203.2248.07001e111962bottom 50
3165plus133.768105.8341060.571042.651544.631556.06391.82-39.8206-131.738-67.9198-239.4794.79738e111962bottom 50
4965plus5879.925403.5712249.213109.612747.320509.110104.4-2073.34-370.562-1045.59-3489.491.24064e111962middle 40
5765plus4387.264023.968633.929015.289036.8419437.47158.54-1244.69-202.224-623.637-2070.559.28289e101962middle 40

download

Some plots

using DataFrames, CairoMakie
using CairoMakie: AbstractPlotting.wong_colors
using LinearAlgebra: dot

agg_df = let
    df1 = select(df,
	    :group_id,
	    :age, :year, wgt, var...
    )
			
    df2 = combine(
	    groupby(df1, :year),
	    ([v, wgt] => ((x,w) -> dot(x,w)/sum(w)) => v for v in var)...
    )
		
    transform!(df2, ([d, inc] => ByRow(/) => string(d) * "2inc" for d in dbt_var)...)
end

let d = agg_df
	fig = Figure()
	
	# Define Layout, Labels, Titles
	Label(fig[1,1], "Growth of Household-Debt-To-Income in the USA", tellwidth = false)
	axs = [Axis(fig[2,1][1,i]) for i in 1:2]
	
	box_attr = (color = :gray90, )
	label_attr = (padding = (3,3,3,3), )
	
	Box(fig[2,1][1,1, Top()]; box_attr...)
	Label(fig[2,1][1,1, Top()], "relative to 1980"; label_attr...)
	
	Box(fig[2,1][1,2, Top()]; box_attr...)
	Label(fig[2,1][1,2, Top()], "relative to total debt in 1980"; label_attr...)
	
	# Plot
	i80 = findfirst(d.year .== 1980)
	
	for (i,dbt) in enumerate(dbt_var)
		var = string(dbt) * "2inc"
		for (j, fractionof) in enumerate([var, :hwdeb2inc])
			lines!(axs[j], d.year, d[!,var]/d[i80,fractionof], label = string(dbt), color = wong_colors[i])
		end
	end

	# Legend
	leg_attr = (orientation = :horizontal, tellheight = true, tellwidth = false)
	leg = Legend(fig[3,1], axs[1]; leg_attr...)

    save("fig_dbt.svg", fig) # hide
	fig
    nothing # hide
end

fig_dbt