text 模拟TS模型中随机效应的偏差

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 模拟TS模型中随机效应的偏差相关的知识,希望对你有一定的参考价值。

* Simulation: Broken or Fixed Effects?

set matsize 5000
clear all

global graph_opts ///
	title(, justification(left) color(black) span pos(11)) ///
	graphregion(color(white) lc(white) lw(med) la(center)) /// <- Delete la(center) for version < 15
	ylab(,angle(0) nogrid) xtit(,placement(left) justification(left)) ///
	yscale(noline) xscale(noline) legend(region(lc(none) fc(none)))

* Run a simulation

	foreach sampleSize of numlist 1 2 3 4 {
		qui forvalues iteration = 1/50 {

			* Create data

				clear 
					// Need an empty dataset
				local nuids = 10^`sampleSize' 
					// Number of units
				set obs `nuids' 
					// Create units
				
				gen fe = rnormal() 
					// Gen fixed effects
				gen uid = _n 
					// Gen unit IDs
				expand 10 
					// Create panel structure
				bys uid: gen period = _n
					// Time structure
				
				gen x_vary = rnormal() + fe 
					// Time-variant characteristics correlated with FEs
				gen y = x_vary + fe + rnormal() 
					// True DGP includes correlated X's and FE's – violates RE assumption

			* Run a regression

				xtset uid
					// Prep for [xtreg]
			
				xtreg y x_vary
					// The biased regression
				local err_re = abs(1-_b[x_vary])
					// Store the error
			
				xtreg y x_vary , fe
					// The unbiased regression
				local err_fe = abs(1-_b[x_vary])
					// Store the error
			
				mat results = /// All data to matrix
					nullmat(results) \ [`err_re',`err_fe',`nuids']

		}
	}

* Visualize the simulation

	clear
	svmat results

	tw ///
		(lpolyci results1 results3 , lw(thick)) ///
		(lpolyci results2 results3 , lw(thick)) ///
	, ${graph_opts} ///
		xscale(log) xlab(10 100 1000 10000) ///
		xtitle("Observations{&rarr}") ///
		ytitle(" ") yline(0 , lw(thin)) ///
		legend(c(1) ring(0) pos(3) ///
			order(0 "Average Error:" 2 "Random Effects" 4 "Fixed Effects"))

* Have a lovely day!

以上是关于text 模拟TS模型中随机效应的偏差的主要内容,如果未能解决你的问题,请参考以下文章

在 mclogit 中编码随机效应

spss广义估计方程 模型效应检验 qic多大好

GWAS基本建模原理

r语言孟德尔随机化分析,怎么把ivw改成随机效应模型

全基因组选择的模型汇总(转载)

R语言构建随机森林模型randomForest分类模型并评估模型在测试集和训练集上的效果(accurayF1偏差Deviance):随机森林在Bagging算法的基础上加入了列采样(分枝特征随机)