* EconS 512 HW 2 * Jiehong Qiu * 10 Nov. 2016 cd "C:\Users\qjhws\Desktop\Classes\512TA\HW2" import delimited C:\Users\qjhws\Desktop\Classes\512TA\HW2\time_var.txt,clear preserve import delimited C:\Users\qjhws\Desktop\Classes\512TA\HW2\time_invar.txt,clear save "C:\Users\qjhws\Desktop\Classes\512TA\HW2\invar.dta",replace restore merge m:1 personid using invar.dta, nogen * Model 1 reg logwage education experience timetrend est store m1 * Model 2 reg logwage education experience timetrend ability mothereducation /// fathereducation brokenhome numbersiblings est store m2 * Model 3 xtset personid xtreg logwage education experience timetrend,fe xtreg logwage education experience timetrend ability mothereducation /// fathereducation brokenhome numbersiblings,fe est store m3 * Model 4 xtreg logwage education experience timetrend ability mothereducation /// fathereducation brokenhome numbersiblings,re est store m4 * Model 5 egen IV1 = mean(experience),by(personid) gen IV2 = experience - IV1 ivregress 2sls logwage brokenhome numbersiblings timetrend mothereducation fathereducation (education ability = IV1 IV2) predict res, residual *number of panel egen tag_id = tag(personid) count if personid != 0 // total observation scalar total_obs = r(N) count if tag_id == 1 // number of panel scalar num_ind = r(N) * we calculate the variance using Baltagi and Chang(2000) gen res_2 = res^2 sum res_2 // we will use r(sum) scalar sigma_v = r(sum)/(total_obs-num_ind) scalar sigma_vSq = sigma_v^2 egen groupMean_res = mean(res), by(personid) gen groupMean_resSqr = groupMean_res^2 gen sigma_v2 = sigma_v^2 sum groupMean_resSqr scalar sigma_u = (r(sum)-num_ind*(sigma_v2))/total_obs scalar sigma_uSq = sigma_u^2 * re-weight all variables egen num_period = count(personid),by(personid) gen w_i = num_period* sigma_uSq + sigma_vSq gen theta = 1-1/sqrt(sigma_vSq/w_i) global varList "logwage brokenhome numbersiblings timetrend mothereducation fathereducation education ability IV1 IV2" foreach var of global varList{ egen `var'_mean = mean(`var'),by(personid) gen demean_`var' = `var' - theta*`var'_mean } ********************************************************************************** cap drop *_mean ivregress 2sls demean_logwage demean_brokenhome demean_numbersiblings demean_timetrend /// demean_mothereducation demean_fathereducation (demean_education demean_ability = demean_IV1 demean_IV2) est store m5 * Model 6 mixed logwage experience timetrend ability mothereducation fathereducation brokenhome numbersiblings || personid : education est store m6 esttab m* using result.csv, replace /// compress nogap b(%6.3f) se pr2 /// star(* 0.1 ** 0.05 *** 0.01)