0
我想使用在高斯统计软件中实现的面板数据计量经济学测试。使用R包MASS::write.matrix
我已经设法生成一个ASCII文件并从高斯内读取文件。这对t x n矩阵很有效。但我想知道如何导出一个t×nk矩阵。 nk列会简单地相互追加吗?如何创建高斯矩阵文件
我想使用在高斯统计软件中实现的面板数据计量经济学测试。使用R包MASS::write.matrix
我已经设法生成一个ASCII文件并从高斯内读取文件。这对t x n矩阵很有效。但我想知道如何导出一个t×nk矩阵。 nk列会简单地相互追加吗?如何创建高斯矩阵文件
使用从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)
这个文件然后可以从高斯与
load datax[t,n*k+1] = gaussmatrix.prn; /* t x nk matrix */
/* Remove the first column with years*/
x = datax[.,2:cols(datax)];
有阅读是推荐的MASS包中的'write.matrix'函数。也可能强迫数据框并使用'write.table'。 –