如何将数据从 EViews 直接导入 MATLAB(不向磁盘写入任何内容)

How to import data from EViews to MATLAB directly (without writing anything to disk)

我想将 EViews(很遗憾我不得不使用的点击式计量经济学软件)数据库中的数据直接导入 MATLAB,而不将任何临时文件写入磁盘。当然,将系列导出为 CSV 或 Excel 并随后将其导入 MATLAB 是很简单的,但这对于大量系列来说效率低下,并且不允许自动化。

EViews 网站上的文档对此进行了介绍:Eviews COM Automation。在 MATLAB 中,创建一个 ActiveX 控件的句柄,并使用它在内存中来回传递数据。

% launch EViews ActiveX server
hm = actxserver('Eviews.Manager') ;
h = hm.GetApplication(0) ;

% load file
h.Run(sprintf('wfuse %s',myPath)) ;

% dates
h.Run(sprintf('string startDate = %s.@first',myVar)) ;
startDate = h.Get('startDate') ;
h.Run(sprintf('string endDate = %s.@last',myVar)) ;
endDate = h.Get('endDate') ;

% drop consecutive leading/trailing missing observations
h.Run(sprintf('smpl %s %s',startDate,endDate)) ;

% transfer values
values = cell2mat(h.GetSeries(myVar)) ;

h.release ;

注意有一些启动时间,因为必须等待Eviews在后台启动才能使用,所以如果要导入多个系列,建议在创建后插入循环ActiveX 控件的句柄。

另请注意,这不适用于所有版本的 Eviews。如果遇到困难,请先联系制造商以获得补丁。