Macroeconomics data via FRED

for Mulligan, Casey B.  “Expectations, Means-tested Subsidies, and Economic Performance during the Recession.”  Journal of Mathematical Finance.  2017.

This notebook cannot be run without an API key from the Federal Reserve Bank of St. Louis.  The notebook is provided in order to document how the paper’s macroeconomic series were constructed from FRED series.

The results of this notebook were saved in June 2017 to the local file “JMFFRED” provided with the paper’s backup.

Utilities

TimeSeries

lagoneqtr[series_TemporalData]:=TimeSeriesShift[series,{1,"Quarter"}]

AccumulateTimeSeries[series_TemporalData]:=Accumulate@TimeSeries@Normal@series

FRED data

Make FRED connection

(* when the dialog box appears, enter your FRED API key *)
fred=ServiceConnect["FederalReserveEconomicData"]

Download hours data

indexcomponentsdb=Dataset@Association@(Rule[#,fred["SeriesData","ID"->#,"Date"->{DateString[{2007,1,1},{"Year","-","Month","-","Day"}],DateString[{2013,12,1},{"Year","-","Month","-","Day"}]}]]&/@{"AWHAETP","CNP16OV","PAYEMS","LNS12027714","LNS12032184"})

hrsperadult=indexcomponentsdb[#AWHAETP*(#PAYEMS+#LNS12027714+#LNS12032184)/#CNP16OV&]

idxbase=Mean@TimeSeriesWindow[hrsperadult,{{2007,1},{2007,12}}]

hrsperadultindex=(hrsperadult/idxbase);

quarterlyagglabor=TimeSeriesShift[TimeSeriesShift[TimeSeriesAggregate[indexcomponentsdb[#AWHAETP*(#PAYEMS+#LNS12027714+#LNS12032184)&],"Quarter"],{-14,"Day"}],{-1,"Month"}](* dated to beginning of quarter *);

Download government consumption and investment data

govconsseries=Dataset@Association@(Rule[#,fred["SeriesData","ID"->#,"Date"->{DateString[{2005,1,1},{"Year","-","Month","-","Day"}],DateString[{2013,12,1},{"Year","-","Month","-","Day"}]}]]&/@{"A955RA3Q086SBEA","A955RC1Q027SBEA","A997RA3Q086SBEA","A997RC1Q027SBEA","A782RA3Q086SBEA","A782RC1Q027SBEA","B788RA3Q086SBEA","Y050RC1Q027SBEA","A808RC1Q027SBEA","Y052RC1Q027SBEA"}/.
{"A955RA3Q086SBEA"->"TotconsQindex",
"A955RC1Q027SBEA"->"TotconsExpend",
"A997RA3Q086SBEA"->"DefconsQindex",
"A997RC1Q027SBEA"->"DefconsExpend",
"A782RA3Q086SBEA"->"TotinvQindex",
"A782RC1Q027SBEA"->"TotinvExpend",
"B788RA3Q086SBEA"->"DefinvQindex",
"Y050RC1Q027SBEA"->"DefequExpend",
"A808RC1Q027SBEA"->"DefstrExpend",
"Y052RC1Q027SBEA"->"DefipiExpend"});

Make a nondefense cons quantity index (2009=100) from the overall quantity index and the defense quantity index

nondefgconqindex=((100Exp@#)/(Mean@Values@TimeSeriesWindow[Exp@#,DateObject/@{{2009,1,1},{2009,12,1}}]))&@AccumulateTimeSeries@(sub2gr/.First@Solve[agggr==sh1 sub1gr+(1-sh1)sub2gr(* equation for the growth rate of a two-component index  *),sub2gr]/.{sh1->(Mean@{#,lagoneqtr@#}&@((govconsseries[#DefconsExpend&])/(govconsseries[#TotconsExpend&]))),
agggr->(Log[((#)/(lagoneqtr@#))]&@govconsseries[#TotconsQindex&]),
sub1gr->(Log[((#)/(lagoneqtr@#))]&@govconsseries[#DefconsQindex&])});

Make a nondefense inv quantity index (2009=100) from the overall quantity index and the defense quantity index

nondefginvqindex=((100Exp@#)/(Mean@Values@TimeSeriesWindow[Exp@#,DateObject/@{{2009,1,1},{2009,12,1}}]))&@AccumulateTimeSeries@(sub2gr/.First@Solve[agggr==sh1 sub1gr+(1-sh1)sub2gr(* equation for the growth rate of a two-component index  *),sub2gr]/.{sh1->(Mean@{#,lagoneqtr@#}&@((govconsseries[#DefequExpend&]+govconsseries[#DefstrExpend&]+govconsseries[#DefipiExpend&])/govconsseries[#TotinvExpend&])),
agggr->(Log[((#)/(lagoneqtr@#))]&@govconsseries[#TotinvQindex&]),
sub1gr->(Log[((#)/(lagoneqtr@#))]&@govconsseries[#DefinvQindex&])});

Download private consumption and pop data

pvtconsseries=Dataset@Association@(Rule[#,fred["SeriesData","ID"->#,"Date"->{DateString[{2005,1,1},{"Year","-","Month","-","Day"}],DateString[{2013,12,1},{"Year","-","Month","-","Day"}]}]]&/@{"PCNDGC96","PCND","PCESVC96","PCESV","POPTHM"}/.
{"PCNDGC96"->"NondurQindex",
"PCND"->"NondurExpend",
"PCESVC96"->"ServicesQindex",
"PCESV"->"ServicesExpend"});

Make a private + public (nondefense) consumption quantity index (2009=100).

privatepublicexpend=pvtconsseries[#NondurExpend&]+pvtconsseries[#ServicesExpend&]+govconsseries[#TotconsExpend&]-govconsseries[#DefconsExpend&];

privatepublicQindex=((100Exp@#)/(Mean@Values@TimeSeriesWindow[Exp@#,DateObject/@{{2009,1,1},{2009,12,1}}]))&@AccumulateTimeSeries@((sh1 sub1gr + sh2 sub2gr+(1-sh1-sh2)sub3gr)/.
{sh1->(Mean@{#,lagoneqtr@#}&@((pvtconsseries[#NondurExpend&])/privatepublicexpend)),
sh2->(Mean@{#,lagoneqtr@#}&@((pvtconsseries[#ServicesExpend&])/privatepublicexpend)),
sub1gr->(Log[((#)/(lagoneqtr@#))]&@pvtconsseries[#NondurQindex&]),
sub2gr->(Log[((#)/(lagoneqtr@#))]&@pvtconsseries[#ServicesQindex&]),
sub3gr->(Log[((#)/(lagoneqtr@#))]&@nondefgconqindex)});

quarterlypop=TimeSeriesShift[TimeSeriesShift[TimeSeriesAggregate[pvtconsseries[#POPTHM&],"Quarter"],{-14,"Day"}],{-1,"Month"}];(* dated to beginning of quarter *)

Download production and investment data

prodseries=Dataset@Association@(Rule[#,fred["SeriesData","ID"->#,"Date"->{DateString[{2005,1,1},{"Year","-","Month","-","Day"}],DateString[{2013,12,1},{"Year","-","Month","-","Day"}]}]]&/@{"GDPC1","PCDGCC96","PCDG","GPDIC96","GPDI","PRFIC96","PRFI"});

laborproductivity=((prodseries[#GDPC1&])/quarterlyagglabor);

Make a private + public (nondefense) investment quantity index (2009=100).

privatepublicinvexpend=prodseries[#PCDG&]+prodseries[#GPDI&]+govconsseries[#TotinvExpend&]-(govconsseries[#DefequExpend&]+govconsseries[#DefstrExpend&]+govconsseries[#DefipiExpend&]);

privatepublicinvqindex=((100Exp@#)/(Mean@Values@TimeSeriesWindow[Exp@#,DateObject/@{{2009,1,1},{2009,12,1}}]))&@AccumulateTimeSeries@((sh1 sub1gr + sh2 sub2gr+(1-sh1-sh2)sub3gr)/.
{sh1->(Mean@{#,lagoneqtr@#}&@((prodseries[#PCDG&])/privatepublicinvexpend)),
sh2->(Mean@{#,lagoneqtr@#}&@((prodseries[#GPDI&])/privatepublicinvexpend)),
sub1gr->(Log[((#)/(lagoneqtr@#))]&@prodseries[#PCDGCC96&]),
sub2gr->(Log[((#)/(lagoneqtr@#))]&@prodseries[#GPDIC96&]),
sub3gr->(Log[((#)/(lagoneqtr@#))]&@nondefginvqindex)});

privatepublicinvqindexwohousing=((100Exp@#)/(Mean@Values@TimeSeriesWindow[Exp@#,DateObject/@{{2009,1,1},{2009,12,1}}]))&@AccumulateTimeSeries@(sub2gr/.First@Solve[agggr==sh1 sub1gr+(1-sh1)sub2gr(* equation for the growth rate of a two-component index  *),sub2gr]/.{sh1->(Mean@{#,lagoneqtr@#}&@((prodseries[#PRFI&])/privatepublicinvexpend)),
agggr->(Log[((#)/(lagoneqtr@#))]&@privatepublicinvqindex),
sub1gr->(Log[((#)/(lagoneqtr@#))]&@prodseries[#PRFIC96&])});

Save to local file

AppendTo[LocalSymbol[NotebookDirectory[]<>"JMFFRED"],
<|"timestamp"->Now,
"sourcenotebook"->"JMFFRED.nb",
"hrsperadultindex"->hrsperadultindex,
"privatepublicQindex"->privatepublicQindex,
"quarterlypop"->quarterlypop,
"laborproductivity"->laborproductivity,
"privatepublicinvqindex"->privatepublicinvqindex,
"privatepublicinvqindexwohousing"->privatepublicinvqindexwohousing
|>];