/********Stata code used to run regressions on productivity vs equality***/
/*****series using 57 core territories: 48 main countries + 9 subregions**/



#delimit;
clear all;
set more off;
set maxvar 6000;
do Codes/doglobalvariables.txt;


/***preparing regression file with 48 main countries***/
use Data/equality.dta, clear;
keep year sy1050* prod*;
reshape long sy1050 prod, i(year) j(country) string;
gen equal=1/sy1050;
drop sy1050;
/***keep only the 48 main countries***/
gen maincountry=0;
foreach c of global maincountries
{;
replace maincountry=1 if country=="`c'";
};
keep if maincountry==1;
drop maincountry;
gen lprod=log(prod);
gen lequal=log(equal);
save Data/reg.dta, replace;
/***preferred basic specifications prod vs equal with 48 main countries***/
use Data/reg.dta, clear;
reg prod equal if year==2025;
reg prod equal if year==1980;
reg prod equal if year==1950;
reg prod equal if year==1910;
reg lprod lequal if year==2025;
reg lprod lequal if year==1980;
reg lprod lequal if year==1950;
reg lprod lequal if year==1910;
xi: reg lprod lequal;
xi: reg lprod lequal i.country;
xi: reg lprod lequal i.country i. year;


/***preparing regression file with 8 world regions***/
use Data/equality.dta, clear;
keep year sy1050* prod*;
reshape long sy1050 prod, i(year) j(country) string;
gen equal=1/sy1050;
drop sy1050;
keep if country=="EURO" | country=="NAOC" | country=="EASA" | country=="LATA" | country=="MENA" | country=="SSAF" | country=="EASA" | country=="SSEA";
gen lprod=log(prod);
gen lequal=log(equal);
save Data/regregion.dta, replace;
/***preferred specifications with 8 world regions***/
use Data/regregion.dta, clear;
reg prod equal if year==2025;
reg prod equal if year==1980;
reg prod equal if year==1950;
reg prod equal if year==1910;
reg lprod lequal if year==2025;
reg lprod lequal if year==1980;
reg lprod lequal if year==1950;
reg lprod lequal if year==1910;

/***importing human k variables**/
use "D:\Users\t.piketty\Dropbox\GJP2026HumanK\Paper\Data\humankprodreg.dta", clear; 
keep year country htot hpub hpri edutot edupub edupri heatot heapub heapri;
merge 1:1 year country using Data/reg.dta;
keep if _merge==3;
drop _merge;
order year country prod equal;
save Data/reghumank.dta, replace;
/***computing cumulated equality index and human k invt of previous 30 years***/
forvalues j=1830/2025
{;
use Data/reghumank.dta, clear;
keep if year>=`j'-30 & year<=`j';
collapse equal htot hpub hpri edutot edupub edupri heatot heapub heapri, by(country);
rename * *30;
rename country30 country;
gen year=`j';
merge 1:1 country year using Data/reghumank.dta;
drop _merge;
save Data/reghumank.dta, replace;
};
order country year prod equal;
sort country year;
gen gprod30=(prod/prod[_n-30])^(1/30)-1;
gen lequal30=log(equal30);
drop if year<1830;
save Data/reghumank.dta, replace;
/***defining productivity intervals***/
use Data/reghumank.dta, clear;
gen Ii=1 if prod<4;
replace Ii=2 if prod>=4 & prod<10;
replace Ii=3 if prod>=10 & prod<20;
replace Ii=4 if prod>=20 & prod<36;
replace Ii=5 if prod>=36;
save Data/reghumank.dta, replace;
/***computing average human capital expenditure by productivity interval***/
use Data/reghumank.dta, clear;
collapse (mean) edupub edupri edutot heapub heapri heatot hpub hpri htot, by(Ii);
rename * I*;
rename IIi Ii;
merge 1:n Ii using Data/reghumank.dta;
drop _merge;
order country year prod;
sort country year;
save Data/reghumank.dta, replace;
/***computing differential human capital expenditure by productivity interval***/
use Data/reghumank.dta, clear;
foreach k in htot hpub hpri edutot edupub edupri heatot heapub heapri
{;
gen d`k'30=`k'30-I`k';
};
order country year prod;
sort country year;
save Data/reghumank.dta, replace;

/****preferred specifications (01-04-25)***/
use Data/reghumank.dta, clear;
/***determinants of productivity level 2020-2025**/
reg prod equal30 if year>=1990;
reg prod equal30 htot30 if year>=1990;
reg prod equal30 htot30 edutot30 if year>=1990;
reg lprod lequal30 if year>=1990;
reg lprod lequal30 htot30 if year>=1990;
reg lprod lequal30 htot30 edutot30 if year>=1990;
/***determinants of productivity growth rates 1830-2025***/
reg gprod30 equal30;
xi: reg gprod30 equal30 i.country;
xi: reg gprod equal30 htot30 i.country;
xi: reg gprod equal30 htot30 edutot30 i.country;
/***pb 01-04-25: very unstable results; in particular, with equality, the impact of educ becomes negative, even after including reconstruction and asianmiracle dummies**/


/*
gen reconstruction=0;
replace reconstruction=1 if (year>=1950 & year<=1980) & (country=="DE" | country=="DK" | country=="FR" | country=="GB" | country=="IT" | country=="ES" | country=="NL" | country=="NO" |country=="SE" | country=="TW" | country=="JP" | country=="KR");
gen asiamiracle=0;
replace asiamiracle=1 if (year>=1990 & year<=2025) & (country=="CN" | country=="IN" | country=="ID" | country=="VN");



