#delimit;
set more 1;
set memory 750m;
set matsize 400;

log using "/Volumes/Ddisk/BGH/Programs/Table 1/rsquared.log", replace;



use "/Volumes/Ddisk/BGH/Programs/Table 1/wage_m.dta", clear;

gen code1=survey*10 + edcode;
gen code2=survey*100 + expcode;
gen code3=expcode*10 + edcode;
tab edcode, gen(educ);
tab survey, gen(year);
tab expcode, gen(xp);
tab code1, gen(inter);
tab code2, gen(intra);
tab code3, gen(extra);

*DEFINE QUANTITES BASED ON COUNTS OF WORKERS USING HOURS WORKED;
gen lmrelm=log(immigm/nativem);
gen lmrelf=log((immig-immigm)/(native-nativem));
gen lmrelmf=log(immig/native);
gen lmpm=log(pimmigm/pnativem);
gen lmpf=log(pimmig-pimmigm)-log(pnative-pnativem);
gen lmpmf=log(pimmig/pnative);

gen logrelweek1=lweeklyi-lweeklyn;
gen relweek1=log(weeklyi/weeklyn);

generate varweightlog=(slweeklyn^2/sizewn) + (slweeklyi^2/sizewi);
replace varweightlog=1/varweightlog;

reg logrelweek1 lmrelm [aw=varweightlog], cluster(code3);
reg logrelweek1 lmrelm year* [aw=varweightlog], cluster(code3);
reg logrelweek1 lmrelm year* extra* [aw=varweightlog], cluster(code3);
reg logrelweek1 lmrelm inter* intra* extra* [aw=varweightlog], cluster(code3);

reg logrelweek1 lmrelm [aw=varweightlog] ;
reg logrelweek1 lmrelm year* [aw=varweightlog] ;
reg logrelweek1 lmrelm year* extra* [aw=varweightlog] ;
reg logrelweek1 lmrelm inter* intra* extra* [aw=varweightlog] ;




use "/Volumes/Ddisk/BGH/Programs/Table 1/wage_m_ft.dta", clear;

gen code1=survey*10 + edcode;
gen code2=survey*100 + expcode;
gen code3=expcode*10 + edcode;
tab edcode, gen(educ);
tab survey, gen(year);
tab expcode, gen(xp);
tab code1, gen(inter);
tab code2, gen(intra);
tab code3, gen(extra);

*DEFINE QUANTITES BASED ON COUNTS OF WORKERS USING HOURS WORKED;
gen lmrelm=log(immigm/nativem);
gen lmrelf=log((immig-immigm)/(native-nativem));
gen lmrelmf=log(immig/native);
gen lmpm=log(pimmigm/pnativem);
gen lmpf=log(pimmig-pimmigm)-log(pnative-pnativem);
gen lmpmf=log(pimmig/pnative);

gen logrelweek1=lweeklyi-lweeklyn;
gen relweek1=log(weeklyi/weeklyn);

generate varweightlog=(slweeklyn^2/sizewn) + (slweeklyi^2/sizewi);
replace varweightlog=1/varweightlog;

reg logrelweek1 lmrelm [aw=varweightlog], cluster(code3);
reg logrelweek1 lmrelm year* [aw=varweightlog], cluster(code3);
reg logrelweek1 lmrelm year* extra* [aw=varweightlog], cluster(code3);
reg logrelweek1 lmrelm inter* intra* extra* [aw=varweightlog], cluster(code3);

reg logrelweek1 lmrelm [aw=varweightlog] ;
reg logrelweek1 lmrelm year* [aw=varweightlog] ;
reg logrelweek1 lmrelm year* extra* [aw=varweightlog] ;
reg logrelweek1 lmrelm inter* intra* extra* [aw=varweightlog] ;



use "/Volumes/Ddisk/BGH/Programs/Table 1/wage_mf.dta", clear;

gen code1=survey*10 + edcode;
gen code2=survey*100 + expcode;
gen code3=expcode*10 + edcode;
tab edcode, gen(educ);
tab survey, gen(year);
tab expcode, gen(xp);
tab code1, gen(inter);
tab code2, gen(intra);
tab code3, gen(extra);

*DEFINE QUANTITES BASED ON COUNTS OF WORKERS USING HOURS WORKED;
gen lmrelm=log(immigm/nativem);
gen lmrelf=log((immig-immigm)/(native-nativem));
gen lmrelmf=log(immig/native);
gen lmpm=log(pimmigm/pnativem);
gen lmpf=log(pimmig-pimmigm)-log(pnative-pnativem);
gen lmpmf=log(pimmig/pnative);

gen logrelweek1=lweeklyi-lweeklyn;
gen relweek1=log(weeklyi/weeklyn);

generate varweightlog=(slweeklyn^2/sizewn) + (slweeklyi^2/sizewi);
replace varweightlog=1/varweightlog;

reg logrelweek1 lmrelmf [aw=varweightlog], cluster(code3);
reg logrelweek1 lmrelmf year* [aw=varweightlog], cluster(code3);
reg logrelweek1 lmrelmf year* extra* [aw=varweightlog], cluster(code3);
reg logrelweek1 lmrelmf inter* intra* extra* [aw=varweightlog], cluster(code3);

reg logrelweek1 lmrelmf [aw=varweightlog] ;
reg logrelweek1 lmrelmf year* [aw=varweightlog] ;
reg logrelweek1 lmrelmf year* extra* [aw=varweightlog] ;
reg logrelweek1 lmrelmf inter* intra* extra* [aw=varweightlog] ;




use "/Volumes/Ddisk/BGH/Programs/Table 1/wage_mf_ft.dta", clear;

gen code1=survey*10 + edcode;
gen code2=survey*100 + expcode;
gen code3=expcode*10 + edcode;
tab edcode, gen(educ);
tab survey, gen(year);
tab expcode, gen(xp);
tab code1, gen(inter);
tab code2, gen(intra);
tab code3, gen(extra);

*DEFINE QUANTITES BASED ON COUNTS OF WORKERS USING HOURS WORKED;
gen lmrelm=log(immigm/nativem);
gen lmrelf=log((immig-immigm)/(native-nativem));
gen lmrelmf=log(immig/native);
gen lmpm=log(pimmigm/pnativem);
gen lmpf=log(pimmig-pimmigm)-log(pnative-pnativem);
gen lmpmf=log(pimmig/pnative);

gen logrelweek1=lweeklyi-lweeklyn;
gen relweek1=log(weeklyi/weeklyn);

generate varweightlog=(slweeklyn^2/sizewn) + (slweeklyi^2/sizewi);
replace varweightlog=1/varweightlog;

reg logrelweek1 lmrelmf [aw=varweightlog], cluster(code3);
reg logrelweek1 lmrelmf year* [aw=varweightlog], cluster(code3);
reg logrelweek1 lmrelmf year* extra* [aw=varweightlog], cluster(code3);
reg logrelweek1 lmrelmf inter* intra* extra* [aw=varweightlog], cluster(code3);

reg logrelweek1 lmrelmf [aw=varweightlog] ;
reg logrelweek1 lmrelmf year* [aw=varweightlog] ;
reg logrelweek1 lmrelmf year* extra* [aw=varweightlog] ;
reg logrelweek1 lmrelmf inter* intra* extra* [aw=varweightlog] ;


log close;

