/* Macro ARMALOOP for simulations of MLE for an ARMA(1,1) model,
which will then be collected to data file ARMA11. The statitistics
of the data set of simulations are output to data SIMSTAT */
%macro armaloop(mu=, sigma=, phi=, theta=, sim=, n=, seed=);
data ARMA11 ; /* initialize data set */
run;
/******* Macro do-loop for simulations and their MLE starts *******/
/* where macro variable &j is only for conuting, not as an input */
%do j=1 %to ∼
proc iml; /*start iml software */
n = &n;
seed=&seed;
mu = μ
sigma = σ
phi = {1 &phi }; /* exact AR coefficients on LHS of model */
theta = {1 &theta }; /* exact MA coefficients on RHS of model */
yt = armasim(phi, theta, mu, sigma, n, seed); /* generate series*/
create yt from yt [colname='yt']; /* store it in data set for analysis */
append from yt;
close yt;
proc arima data=yt;
identify var=yt noprint ;
estimate p=1 q=1 method=ml maxiter=100 outest=EST noprint /* ar=&phi ma=&theta */ ;
run;
data EST;
seed=&seed;
set EST (where=(_type_="EST"));
dev_ar=abs(ar1_1- (-&phi)) / abs(-&phi) ; 这里为什么是-&phi和-&theta呢?
dev_ma=abs(ma1_1 - (-&theta)) / abs(&theta) ;
drop _type_ ;
data ARMA11 ; /* add new estimates to ARMA11 */
set ARMA11 EST;
if seed=. then delete;
run;
%let seed=%eval(1+&seed); /* add 1 to seed number */
%end;
/*********** macro do-loop ends *********/
proc capability data=ARMA11 noprint;
par = (1-(&theta)*(&phi))/((&theta)-(&phi));
sig_ar = sqrt((1-(&phi)**2) /(&n))*par;
cdfplot ar1_1 / normal(mu=&phi sigma=sig_ar color=red);
run;
%mend armaloop;
/******* macro armaloop ends ***********/
/****** macro COLLECTION for repeating macro ARMALOOP begins *******/
%macro collect;
data simstat; run; /* initialize data SIMATAT for collecting statistics */
%do n=60 % to 80 %by 10;
%armaloop (mu=10, sigma=1, phi=-0.1, theta=0.1, sim=2, n=&n, seed=3307);
/*data simstat; set simstat statARMA11; if sim=. then delete; run;*/
%end;
%mend collect;
/******macro COLLECTION ends*******/
%collect /*run macro COLLECTION*/
关于蓝色字体部分,run出的结果如下:
NOTE: Line generated by the invoked macro "ARMALOOP".
11 proc capability data=ARMA11 noprint; par = (1-(&theta)*(&phi))/((&theta)-(&phi));
---
180
NOTE: Line generated by the invoked macro "ARMALOOP".
12 sig_ar = sqrt((1-(&phi)**2) /(&n))*par; cdfplot ar1_1 / normal(mu=&phi sigma=sig_ar color=red); run;
----- ----- -----
180 22 202
ERROR 180-322: Statement is not valid or it is used out of proper order.
ERROR 22-322: Syntax error, expecting one of the following: a numeric constant, a datetime constant.
ERROR 202-322: The option or parameter is not recognized and will be ignored.
不明白啊不明白啊。。。要怎么办好呀。。。。



雷达卡


京公网安备 11010802022788号







