Untitled
unknown
plain_text
9 months ago
4.9 kB
12
Indexable
clear
cd "C:\Users\rlawl\OneDrive\바탕 화면\25년 2학기\고급도시환경분석\assignment\Assignment2_panel\"
* Looking at Panel data
use nlswork471, clear
**list idcode year wage south grade if inrange(idcode, 1, 10) , noobs sepby(idcode)
list idcode year not_smsa wage south grade race2 if inrange(idcode, 1, 10) , noobs sepby(idcode)
*--------------------------------------------------------------------------------
* Generate key variables
*--------------------------------------------------------------------------------
hist wage
hist grade
hist age
* Log-transformation of wage
gen ln_wage = ln(wage+1)
hist ln_wage
codebook race
codebook south
codebook not_smsa
codebook union
* drop Race == others
drop if race == 3
gen black = race == 2
* rescale year
gen year1 = year - 1967
*----------------------------------------------------------------------------
* Descriptive Statistics of L1 Variables
* 빈도분석은 이산적 변수값, 평균 분석은 연속적 변수 값을 분석 대상으로 함.
*----------------------------------------------------------------------------
format ln_wage year1 south not_smsa union age %9.3f
summarize ln_wage year1 south not_smsa union age
*--------------------------------------------------------------------------------
* Descriptive Statistics of L2 Variables
*--------------------------------------------------------------------------------
* First, let's create a new variable called "count" to distinguish the cases
* within each school. To do this, we make use of the "_n" variable, which is
* automatically generated by the software to distinguish rows in the dataset.
* It takes on integer values, starting at 1 (here, within each school):
bysort idcode: gen count=_n
sum black grade if count == 1
sum black grade
*--------------------------------------------------------------------------------
* Explore bivariate distribution of outcome, ln_wage, across & within respondants.
*--------------------------------------------------------------------------------
pwcorr ln_wage not_smsa year1 age south black , sig star(.05)
graph matrix ln_wage year1 age grade // 연속변수만 포함
graph box wage if not_smsa == 1, over(year)
graph box wage if not_smsa == 0, over(year)
graph box ln_wage if not_smsa == 1, over(year)
graph box ln_wage if not_smsa == 0, over(year)
* 4-C)--------------------------------------------------------------------------------
sort idcode year1
xtset idcode year1
* M1: unconditional model
xtreg ln_wage, re
* M2: add question predictor not_smsa as well as year and year squared
xtreg ln_wage i.not_smsa c.year1 c.year1#c.year1 , re
* M3: add the interaction term between not_smsa and (year and year squared)
xtreg ln_wage i.not_smsa c.year1 c.year1#c.year1 i.not_smsa#c.year1 i.not_smsa#c.year1#c.year1, re
* M4: add the time-variant covariates
xtreg ln_wage i.not_smsa c.year1 c.year1#c.year1 i.not_smsa#c.year1 i.not_smsa#c.year1#c.year1 i.south, re
* M5: add the time-invariant covariates
xtreg ln_wage i.not_smsa c.year1 c.year1#c.year1 i.not_smsa#c.year1 i.not_smsa#c.year1#c.year1 i.south i.black c.grade, re
xttest0
mixed ln_wage i.not_smsa c.year1 c.year1#c.year1 i.not_smsa#c.year1 i.not_smsa#c.year1#c.year1 i.south i.black c.grade || idcode:, mle
* 4-D)--------------------------------------------------------------------------------
* 5-A)--------------------------------------------------------------------------------
* M6: M5 + fixed effect
xtreg ln_wage i.not_smsa c.year1 c.year1#c.year1 i.not_smsa#c.year1 i.not_smsa#c.year1#c.year1 i.south i.black c.grade, fe
* 5-B)--------------------------------------------------------------------------------
* M5 (Random effects) 추정 및 저장
xtreg ln_wage i.not_smsa c.year1 c.year1#c.year1 i.not_smsa#c.year1 i.not_smsa#c.year1#c.year1 i.south i.black c.grade, re
estimates store re_model
* M6 (Fixed effects) 추정 및 저장
xtreg ln_wage i.not_smsa c.year1 c.year1#c.year1 i.not_smsa#c.year1 i.not_smsa#c.year1#c.year1 i.south i.black c.grade, fe
estimates store fe_model
* Hausman test
hausman fe_model re_model, sigmamore
* 6-B)--------------------------------------------------------------------------------
xtreg ln_wage i.not_smsa c.year1 c.year1#c.year1 i.not_smsa#c.year1 i.not_smsa#c.year1#c.year1 i.south i.black c.grade, fe
* year1의 범위에 대해 예측값 계산
margins, at(year1=(0 (1) 21) not_smsa=(0 1))
* 플롯 생성
marginsplot, xtitle("Years") ytitle("Predicted Log Wage") legend(order(1 "Metropolitan (SMSA)" 2 "Non-metropolitan (Not SMSA)") position(6) rows(1)) scheme(s2color) name(fig1, replace) xlabel(1 (1) 21, format(%9.0f))
Editor is loading...
Leave a Comment