car38_0 | car39_0 | car40_0 | car41_0 | car42_0 | car44_0 | car45_0 | car46_0 |
1.737921 | 2.468084 | 1.182506 | 1.505058 | 0.693578 | 0.940331 | -2.71841 | -0.13494 |
问题1:我希望生成一个新的变量car_0,为上述后缀为_0的变量对应数值的平均值,这个在stata中如何才能实现?
因为这样后缀为0的car`i'变量太多,手动计算很麻烦,我用最笨的方法试着算了下,结果显示错误。问题2:forvalues命令中还能嵌入forvalues命令吗?像下面generate各公司的car,我本来希望用forvalues来生成,但显示错误。
我的命令如下:
forvalues k=0/20{
mvreg ret1 ret2 ret3 ret4 ret5 ret6 ret7 ret8 ret9 ret11 ret13 ret14 ret15 ret16 ret17 ret18 ret19 ret20 ret21 ret22 ret23 ret24 ret25 ret26 ret27 ret28 ret29 ret30 ret31 ret32 ret33 ret34 ret35 ret36 ret37 ret38 ret39 ret40 ret41 ret42 ret44 ret45 ret46 ret47 ret48 ret49 ret50 ret51 ret52 ret53 ret54 ret55 ret56 ret57 ret58 ret59 ret60 ret61 ret63 ret64 ret65 ret66 ret67 ret68 ret69 ret70 ret71 ret72 ret73 ret74 ret75 ret76 ret77 ret78 ret79 ret80 ret81 ret82 ret83 ret84 ret85 ret86 ret87 ret88 ret89 ret90 ret91 ret92 ret93 ret94 ret95 ret96 ret97 ret98 ret99 ret100 ret101 ret102 ret103 = mar_ret dummy_`k'
gen car1_`k'= (`k'+1)*[ret1]_b[dummy_`k']
...
gen car103_`k'=(`k'+1)*[ret103]_b[dummy_`k'] /*这里我试图用forvalues来分别生成,但似乎不行*/
gen car_`k'=( car1_`k' + car2_`k' + car3_`k'+ car4_`k'+ car5_`k'+ car6_`k'+ car7_`k'+ car8_`k'+ car9_`k'+ car11_`k'+ car13_`k'+ car14_`k'+ car15_`k'+ car16_`k'+ car17_`k'+ car18_`k'+ car19_`k'+ car20_`k'+ car21_`k'+ car22_`k'+ car23_`k'+ car24_`k'+ car25_`k'+ car26_`k'+ car27_`k'+ car28_`k'+ car29_`k'+ car30_`k'+ car31_`k'+ car32_`k'+ car33_`k'+ car34_`k'+ car35_`k'+car36_`k'+ car37_`k'+ car38_`k'+ car39_`k'+ car40_`k'+ car41_`k'+ car42_`k'+ car44_`k'+ car45_`k'+ car46_`k'+ car47_`k'+ car48_`k'+ car49_`k'+ car50_`k'+ car51_`k'+ car52_`k'+ car53_`k'+ car54_`k'+ car55_`k'+ car56_`k'+ car57_`k'+ car58_`k'+ car59_`k'+ car60_`k'+ car61_`k'+ car63_`k'+ car64_`k'+ car65_`k'+ car66_`k'+ car67_`k'+ car68_`k'+ car69_`k'+ car70_`k'+ car71_`k'+ car72_`k'+ car73_`k'+ car74_`k'+ car75_`k'+ car76_`k'+ car77_`k'+ car78_`k'+ car79_`k'+ car80_`k'+ car81_`k'+ car82_`k'+ car83_`k'+ car84_`k'+ car85_`k'+ car86_`k'+ car87_`k'+ car88_`k'+ car89_`k'+ car90_`k'+ car91_`k'+car92_`k'+ car93_`k'+car94_`k'+ car95_`k'+ car96_`k'+ car97_`k'+ car98_`k'+ car99_`k'+ car100_`k'+ car101_`k'+ car102_`k'+ car103_`k')/99 *
}
显示 car_0 not found. error
请教各位同学有什么简单的方法可以解决以上两个问题?看过sum()函数的help手册,但是解决不了问题。
谢谢!