#delimit;
set more 1;
set memory 750m;
set matsize 10000;
log using /volumes/ddisk/bgh/programs/subst_mf_national.log, replace;



*FIRST DO ALL WORKERS;
*I'M USING LESSONS LEARNED FROM EXPERIMENT.DO TO JUST RUN REGRESSIONS IN DIFFERENCED FORMAT;


use /volumes/ddisk/bgh/programs/wage_mf_national.dta, clear;

keep if imm==0;

generate lworked=log(immig+native);
generate lpimm=log(pimmig);

generate trend=survey-1960;
generate t92=max(survey-1992, 0);

generate trend1=(edcode==1)*trend;
generate trend2=(edcode==2)*trend;
generate trend3=(edcode==3)*trend;
generate trend4=(edcode==4)*trend;

keep if edcode<=2;

keep survey edcode lweekly slweekly sizew native immig pnative pimmig;

reshape wide lweekly slweekly sizew native immig pnative pimmig, i(survey) j(edcode);

tab survey, gen(year);

*DEFINE QUANTITES BASED ON COUNTS OF WORKERS USING HOURS WORKED;
gen worked2=native2+immig2;
gen worked1=native1+immig1;
gen dquant21=log(worked2/worked1);
gen dwage21=lweekly2-lweekly1;

gen wsample=(sizew1*sizew2)/(sizew1+sizew2);
gen trend=survey-1960;
gen trend2=trend*trend;
gen trend3=trend*trend*trend;
gen t92=max(survey-1992, 0);
gen t80=max(survey-1980, 0);

generate dimm21=log(immig2/immig1);


reg dwage21 dquant trend t92 [aw=wsample];
reg dwage21 dquant trend [aw=wsample];
reg dwage21 dquant trend trend2 [aw=wsample];
reg dwage21 dquant trend trend2 trend3 [aw=wsample];
reg dwage21 dquant trend t80 [aw=wsample];



generate varweightlog=(slweekly1^2/sizew1) + (slweekly1^2/sizew2);
replace varweightlog=1/varweightlog;


reg dwage21 dquant trend t92 [aw=varweightlog], robust;
reg dwage21 dquant trend [aw=varweightlog], robust;
reg dwage21 dquant trend trend2 [aw=varweightlog], robust;
reg dwage21 dquant trend trend2 trend3 [aw=varweightlog], robust;
reg dwage21 dquant trend t80 [aw=varweightlog], robust;








*NOW DO FULL-TIME WORKERS;




use /volumes/ddisk/bgh/programs/wage_mf_ft_national.dta, clear;

keep if imm==0;

generate lworked=log(immig+native);
generate lpimm=log(pimmig);

generate trend=survey-1960;
generate t92=max(survey-1992, 0);

generate trend1=(edcode==1)*trend;
generate trend2=(edcode==2)*trend;
generate trend3=(edcode==3)*trend;
generate trend4=(edcode==4)*trend;

keep if edcode<=2;

keep survey edcode lweekly slweekly sizew native immig pnative pimmig;

reshape wide lweekly slweekly sizew native immig pnative pimmig, i(survey) j(edcode);

tab survey, gen(year);

*DEFINE QUANTITES BASED ON COUNTS OF WORKERS USING HOURS WORKED;
gen worked2=native2+immig2;
gen worked1=native1+immig1;
gen dquant21=log(worked2/worked1);
gen dwage21=lweekly2-lweekly1;

gen wsample=(sizew1*sizew2)/(sizew1+sizew2);
gen trend=survey-1960;
gen trend2=trend*trend;
gen trend3=trend*trend*trend;
gen t92=max(survey-1992, 0);
gen t80=max(survey-1980, 0);

generate dimm21=log(immig2/immig1);


reg dwage21 dquant trend t92 [aw=wsample];
reg dwage21 dquant trend [aw=wsample];
reg dwage21 dquant trend trend2 [aw=wsample];
reg dwage21 dquant trend trend2 trend3 [aw=wsample];
reg dwage21 dquant trend t80 [aw=wsample];



generate varweightlog=(slweekly1^2/sizew1) + (slweekly1^2/sizew2);
replace varweightlog=1/varweightlog;


reg dwage21 dquant trend t92 [aw=varweightlog], robust;
reg dwage21 dquant trend [aw=varweightlog], robust;
reg dwage21 dquant trend trend2 [aw=varweightlog], robust;
reg dwage21 dquant trend trend2 trend3 [aw=varweightlog], robust;
reg dwage21 dquant trend t80 [aw=varweightlog], robust;



log close;
