0

我想使用在高斯统计软件中实现的面板数据计量经济学检验。使用 R 包MASS::write.matrix,我设法生成了一个 ASCII 文件并从 Gauss 中读取该文件。这适用于 txn 矩阵。但我想知道如何导出 atx nk 矩阵。nk 列会简单地相互附加吗?

4

1 回答 1

0

使用 plm 包中的示例数据集,以下是如何以 atx nk 矩阵格式重塑数据集:

library(dplyr)
library(tidyr)
library(plm) # For the example dataset
data("Produc", package = "plm")
spreadvariable <- c("pcap", "pc", "emp", "unemp")
gaussmatrixfile <- file.path(tempdir(),"gaussmatrix.prn")
gaussmatrixfile
Produc %>%
    select_("year", "state", .dots = spreadvariable) %>% 
    gather(variable, value, -year,-state) %>%
    unite(state_variable, state, variable) %>%
    spread(state_variable, value) %>%
    MASS::write.matrix(gaussmatrixfile)

然后可以从 Gauss 读取这个文件

load datax[t,n*k+1]     = gaussmatrix.prn;        /* t x nk matrix */
/* Remove the first column with years*/
x = datax[.,2:cols(datax)];
于 2016-03-10T16:41:50.503 回答