stata高维面板数据生成
// ssc install egenmore, replace
clear all
set obs 1000000
*---------- 生成高维面板 ----------*
gen source = "CHN"
egen firm = repeat() ,v(1/200)
sort firm
egen citycode = repeat(), v(1/10)
sort firm citycode
egen dest = repeat() , v(1/50)
sort firm citycode dest
egen year = repeat() , v(2011/2020)
*---------- 生成 M var ----------*
gen dist_u = uniform()* 200 + dest * 65
bys dest : egen dist = mean(dist_u)
gen lndist = ln(dist)
drop dist*
*---------- 生成 X var ----------*
gen x = uniform() * 100 + 1/(exp(lndist) * 50)
gen lnx = ln(x)
drop x
*---------- 生成 Y var ----------*
gen value = uniform() * 100 * lndist + 50 * lndist + exp(lnx) * 200
gen lnv = ln(value)
reghdfe lnv lnx ,a(firm dest citycode year)
reghdfe lnv c.lnx##c.lndist ,a(firm citycode dest#year)
reghdfe lnv c.lnx##c.lndist ,a(firm citycode#dest dest#year)