function [Y, y, pai, irate, dy, dpai, dirate, year]= data_1900_2021  
%[Y, y, pai, irate, dy, dpai, dirate, year]= data_1900_2021  
%data_1900_2021.m produces the matlab file data_1900_2021.mat containing annual 
%observations  for 1900 to 2021 of Y = [dy dpai dirate], where  
% dy = growth rate of real U.S. GDP per capita (dy) in percent per year
% 100* ln(y_t/y_t-1);  dpai = change in U.S. CPI inflation rate, units percent per year (pi_t -
% pi_{t-1}); dirate = change in US short-term interest rate, units, percent
% per year, (i_t - i_{t-1})
%The data sources are:  for the period 1900 to 2017 Jorda, Schularick, and Taylor (2017) 
%and for the period 2018-2021  see update_jst.txt 
%Inputs: none
%Outputs: none
% Loads:  
% JSTdatasetR5(1).xlsx
% bea_rgdp.xls
% bea_population.xls
% r-cpi-u-rs-allitems.xlsx
% Saves: 
% data_1900_2021.mat
%Replication materials for: ``What Do Long Data Tell Us About the Inflation Hike Post COVID-19 Pandemic?''
%© Stephanie Schmitt-Grohé and Martín Uribe, December 27, 2023. 

[a,b]=xlsread('JSTdatasetR5(1).xlsx',2);
%for source, date of downloading, and abbreviation of variable names,  see  jst_variables.txt  

country = b(2:end,2);
iso = b(2:end,3);
variable = b(1,:);

%year    
col = find(strcmp(variable,'year'));
rows = find(strcmp(iso,'USA'));
year = a(rows,col);

%rgdppc    Real GDP per capita (index, 2005=100)
col = find(strcmp(variable,'rgdppc'));
rows = find(strcmp(iso,'USA'));
gdppc = a(rows,col);
%add data from BEA for 2018-2021
%for documentation see update_jst.txt
opts = spreadsheetImportOptions("NumVariables", 20);
opts.DataRange = "C8:V8";
newrgdp = readmatrix("bea_rgdp.xls", opts, "UseExcel", false)'; %real GDP
newrgdp = str2double(newrgdp);
opts = spreadsheetImportOptions("NumVariables", 240);
opts.DataRange = "C50:IH50";
beapopulation = readmatrix("bea_population.xls", opts, "UseExcel", false); %population
%for documentation see update_jst.txt
beapopulation = str2double(beapopulation);
beapopulation = reshape(beapopulation,12,20)';
newpop = mean(beapopulation(:,6:7),2); %mean of population in June and July
newgdppc = newrgdp ./ newpop;
newgdppc = newgdppc*100/ newgdppc(4);
gdppc = [gdppc; newgdppc(end-3:end)];

%cpi    Consumer prices (index, 1990=100)
col = find(strcmp(variable,'cpi'));
rows = find(strcmp(iso,'USA'));
cpi = a(rows,col);
pai= diff(log(cpi))*100;
%add data from BLS
opts = spreadsheetImportOptions("NumVariables", 1);
opts.DataRange = "N47:N51";
opts.VariableTypes = "double";
newcpi = readmatrix("r-cpi-u-rs-allitems.xlsx", opts, "UseExcel", false);
%for documentation see update_jst.txt 
newpai = diff(log(newcpi))*100;
pai = [pai; newpai];

%stir      Short-term interest rate (nominal, percent
col = find(strcmp(variable,'stir'));
rows = find(strcmp(iso,'USA'));
irate= a(rows,col);
%add data from MeasuringWorth
opts = delimitedTextImportOptions("NumVariables", 2);
opts.DataLines = [244, Inf];
opts.VariableTypes = ["double", "double"];
newirate = readmatrix("INTERESTRATE_1900-2022.csv", opts);
%for documentation see update_jst.txt 
irate = [irate; newirate(:,2)];

%compute variables
y = log(gdppc);
dy = diff(y)*100;
dpai = diff(pai);
dirate = diff(irate);

%make lengths consistent across variables
year = [year; (2018:2021)'];
year = year(3:end);
y = y(3:end);
dy = dy(2:end);
pai = pai(2:end);
irate = irate(3:end);
dirate = dirate(2:end);

%Start sample in 1900
i0 = find(year==1900);
vars = {'year','y','dy','pai','dpai','irate','dirate'};
for j=1:length(vars)
eval([vars{j} '=' vars{j} '(i0:end);'])
end

Y = [dy dpai dirate];
%save data_1900_2021.mat  year Y y pai irate dy dpai dirate 