FOCUS AREAS

SAS/ETS Examples

Multiple Imputation for a GARCH(1,1) Model


Contents | Back to Example

SAS Program

   /*-----------------------------------------------------------------
     Example: Multiple Imputation with a GARCH(1,1) Model
     Requires: SAS/ETS, SAS/STAT
     Version: 9.0
     ------------------------------------------------------------------*/




   /*
   /* Define n
   /*----------------------------------------------------------------*/
   %let nobs=1000; /* number of obs in the full dataset */

   /*
   /* Generate model data
   /* ---------------------------------------------------------------*/
   data full;
   keep y;
      arch0=0.7; arch1=0.3; garch1=0.4;
         h = arch0 + garch1; /* initialize h */
      do i=-10 to &nobs;
         e = rannor( 101 );
         y = sqrt(h) * e;
         h = arch0 + arch1*y**2 + garch1*h; /* compute h for next step */
         if i > 0 then output; /* burn-in some obs */
      end;
   run;


   /* -- Generate some random missing values --*/
   data missing;
      set full;
      keep y;
      if ranuni(234)<.1 then do;
               /* set random missing values */
         y = .;
               /* count how many missing */
         nmiss+1;
               /* assigns number of missing to macro variable */
         call symput('nmiss', nmiss);
               /* mark the position of the last missing */
         call symput('lastmiss',_n_);
      end;
   run;

   %put Number of missing values = &nmiss;


   title 'Unfeasible Estimation: Complete Dataset';
   proc model data=full;
      parms arch0 arch1 garch1;
      /* Mean zero model --------*/
        y = 0;
      /* Garch Variance ---------*/
        h.y = arch0 + arch1 * xlag( resid.y**2, mse.y) +
              garch1 * xlag( h.y, mse.y ) ;
      /* Fit the garch model ----*/
      fit y   / method=marquardt fiml prl=both outest=full_est outcov;
      bounds arch0 arch1 garch1 >= 0;
   run;
   quit;
   title;


   /*
   /  Multiple Imputation
   /---------------------------------------------------------*/

   %let m=20; /* number of imputations */

   data single;
      set missing;
      if y=. then y=0; /* replace y with mean */
   run;

   proc model data=single;
      parms arch0 arch1 garch1;
      /* Mean zero model --------*/
        y = 0;
      /* Garch Variance ---------*/
        h.y = arch0 + arch1 * xlag( resid.y**2, mse.y) +
              garch1 * xlag( h.y, mse.y ) ;
      /* Fit the garch model ----*/
      fit y   / data=single method=marquardt fiml outest=prelest
                outcov outs=s prl=both;
      bounds arch0 arch1 garch1 >= 0;
      title 'Single imputation';
      run;

      ods listing close; /* close listing output destination */
      /* Impute the missing point in DATA=missing data set */
      solve y / data=missing estdata=prelest sdata=s
                random=&m seed=123 out=monte forecast;


      /* Fit again y with the imputed data */
      fit y   / data=monte(where=(_rep_>0)) method=marquardt fiml
                estdata=prelest sdata=s nools outest=imp_est outcov;
      bounds arch0 arch1 garch1 >= 0;
      by _rep_;
      title 'Multiple Imputation';
   run;

   ods listing; /* open listing again */

   proc print data=missing(firstobs=%eval(&lastmiss-2)
                         obs=%eval(&lastmiss+2));
   title 'Original data set';
   proc print data=monte(firstobs=%eval(&nobs+&lastmiss-2)
                         obs=%eval(&nobs+&lastmiss+2));
       var _rep_ y;
   title 'First set of imputed data';
   proc print data=monte(firstobs=%eval(2*&nobs+&lastmiss-2)
                         obs=%eval(2*&nobs+&lastmiss+2));
       var _rep_ y;
   title 'Second set of imputed data';
   run;
   title;

   data mi_in_est(type=EST);
      set imp_est;
      rename _rep_ = _Imputation_;
      if _name_="" then _type_="PARMS";
      else _type_="COV";
   run;

   proc mianalyze data=mi_in_est edf=&nobs;
      modeleffects arch0 arch1 garch1;
   run;