简体   繁体   English

在SAS中模拟ARMA / ARIMA时间序列过程

[英]Simulating ARMA/ARIMA time series processes in SAS

I've been trying to find the simplest way to generate simulated time series datasets in SAS. 我一直在尝试找到在SAS中生成模拟时间序列数据集的最简单方法。 I initially was experimenting with the LAG operator, but this requires input data, so is proabably not the best way to go. 我最初是在LAG运算符上进行实验,但这需要输入数据,因此可能不是最好的方法。 (See this question: SAS: Using the lag function without a set statement (to simulate time series data.) ) (请参阅此问题: SAS:在没有set语句的情况下使用lag函数(以模拟时间序列数据。)

Has anyone developed a macro or dataset that enables time series to be genereated with an arbitrary number of AR and MA terms? 有没有人开发过宏或数据集,可以使用任意数量的AR和MA项生成时间序列? What is the best way to do this? 做这个的最好方式是什么?

To be specific, I'm looking to generate what SAS calls an ARMA(p,q) process, where p denotes the autoregressive component (lagged values of the dependent variable), and q is the moving average component (lagged values of the error term). 具体来说,我希望生成SAS称为ARMA(p,q)的过程,其中p表示自回归分量(因变量的滞后值),而q是移动平均值分量(误差的滞后值)术语)。

Thanks very much. 非常感谢。

I have developed a macro to attempt to answer this question, but I'm not sure whether this is the most efficient way of doing this. 我已经开发了一个宏来尝试回答这个问题,但是我不确定这是否是最有效的方法。 Anyway, I thought it might be useful to someone: 无论如何,我认为这对某人可能有用:

%macro TimeSeriesSimulation(numDataPoints=100, model=y=e,outputDataSetName=ts, maxLags=10);

data &outputDataSetName (drop=j);
array lagy(&maxlags) _temporary_;
array lage(&maxlags) _temporary_;
/*Initialise values*/

e = 0;
y=0;
t=1;
do j = 1 to 10;
lagy(j) = 0;
lage(j) = 0;
end;

output;

do t = 2 to &numDataPoints;  /*Change this for number of observations*/

    /*SPECIFY MODEL HERE*/
    e = rannorm(-1);  /*Draw from a N(0,1)*/
    &model; 

    /*Update values of lags on the moving average and autoregressive terms*/
    do j = &maxlags-1 to 1 by -1;  /*Note you have to do this backwards because otherwise you cascade the current value to all past values!*/
        lagy(j+1) = lagy(j);
        lage(j+1) = lage(j);
    end;
    lagy(1) = y;
    lage(1) = e;

    output;
end;
run;

%mend;

/*Example 1:  Unit root*/
%TimeSeriesSimulation(numDataPoints=1000, model=y=lagy(1)+e)

/*Example 2:  Simple process with AR and MA components*/
%TimeSeriesSimulation(numDataPoints=1000, model=y=0.5*lagy(1)+0.5*lage(1)+e)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM