STATA

가상의 데이타 만들어서 coefficient 분포 테스트하기

시키테이 2020. 12. 3. 04:07
반응형

clear all

set more off

pause on

set obs 1

expand 1000

gen id=_n

gen b_human=.

gen se_human=.

gen t_human=.

gen p_human=.

gen b_non=.

gen se_non=.

gen t_non=.

gen p_non=.

save temp, replace

 

 

forvalues k = 12345 12346 to 13345 {

clear all

set seed `k'

set obs 1

expand 41

gen firmid=_n

expand 15

bysort firmid: gen year=_n

gen human=uniform()<.05

gen non=uniform()<.35

sort firmid year

by firmid: gen human_decay = human[_n-1] + human[_n-2]/2 + human[_n-3]/3

by firmid: gen non_decay = non[_n-1] + non[_n-2]/2 + non[_n-3]/3

areg human human_decay non_decay i.year, absorb(firmid) cluster(firmid)

local b1 = _b[human_decay]

local se1 = _se[human_decay]

local t1=_b[human_decay]/_se[human_decay]

local p1= 2*ttail(e(df_r),abs(`t1'))

local b2 = _b[non_decay]

local se2 = _se[non_decay]

local t2=_b[non_decay]/_se[non_decay]

local p2= 2*ttail(e(df_r),abs(`t2'))

 

clear

use temp

replace b_human= `b1' if id==`k'-12344

replace se_human = `se1' if id==`k'-12344

replace t_human = `t1' if id==`k'-12344

replace p_human = `p1' if id==`k'-12344

replace b_non= `b2' if id==`k'-12344

replace se_non = `se2' if id==`k'-12344

replace t_non = `t2' if id==`k'-12344

replace p_non = `p2' if id==`k'-12344

save temp, replace

}

clear

use temp

 

hist b_human, xline(0) fraction subtitle("The coefficient of prior human errors")

hist p_human, xline(0.05) fraction subtitle("The p-value of prior human errors")

반응형

'STATA' 카테고리의 다른 글

Schemepack: STATA 그림 템플렛 바꾸기  (0) 2022.09.15
dummy variable: table+gen  (0) 2020.05.14