我需要在dolphindb中使用group-by运行回归。每组的回归结果都是一个向量,我想将所有结果堆叠成一个表,将每个系数估计值作为一列。
t=table(1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 as id, rand(1.0, 15) as y, 1..15 as x1, 3 2 9 5 0 6 7 8 9 10 3 5 0 8 0 as x2)
select ols(y, (x1, x2)) from t group by id
我收到以下错误消息:
select ols(y, x1, x2) as ols_y from t group by id => The column 'ols(y, x1, x2)' must use aggregate function.
有人知道比使用-for循环更好的方法来堆叠结果吗?
由于ols的结果是每个组的一个向量,您可以通过以下方式在dolphindb中将结果指定为复合列:
t=table(1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 as id, rand(1.0, 15) as y, 1..15 as x1, 3 2 9 5 0 6 7 8 9 10 3 5 0 8 0 as x2)
select ols(y, (x1, x2)) as `intercept`x1`x2 from t group by id