def construct_model(key):
model, nendog, nexog, ninstr, weighted, var, other = key.split('-')
var = var.replace('wmatrix', 'vce')
mod = MODELS[model]
data = SIMULATED_DATA
endog = data[['x1', 'x2']] if '2' in nendog else data.x1
exog = data[['x3', 'x4', 'x5']]
instr = data[['z1', 'z2']] if '2' in ninstr else data.z1
deps = {'vce(unadjusted)': data.y_unadjusted,
'vce(robust)': data.y_robust,
'vce(cluster cluster_id)': data.y_clustered,
'vce(hac bartlett 12)': data.y_kernel}
dep = deps[var]
if 'noconstant' not in other:
exog = sm.add_constant(data[['x3', 'x4', 'x5']])
cov_opts = deepcopy(SIMULATED_COV_OPTIONS[var])
cov_opts['debiased'] = 'small' in other
mod_options = {}
if 'True' in weighted:
mod_options['weights'] = data.weights
if model == 'gmm':
mod_options.update(deepcopy(SIMULATED_COV_OPTIONS[var]))
mod_options['weight_type'] = mod_options['cov_type']
del mod_options['cov_type']
mod_options['center'] = 'center' in other
model_result = mod(dep, exog, endog, instr, **mod_options).fit(**cov_opts)
if model == 'gmm' and 'True' in weighted:
pytest.skip('Weighted GMM differs slightly')
return model_result
评论列表
文章目录