Resources

Getting Started Example for PROC MODEL

/*--------------------------------------------------------------

                    SAS Sample Library

        Name: modgs.sas
 Description: Example program from SAS/ETS User's Guide,
              The MODEL Procedure
       Title: Getting Started Example for PROC MODEL
     Product: SAS/ETS Software
        Keys: nonlinear simultaneous equation models
        PROC: MODEL
       Notes:

--------------------------------------------------------------*/

proc model data=sashelp.citimon;
   lhur = 1/(a * ip + b) + c;
   fit lhur;
run;

title1 'Supply-Demand Model using General-form Equations';
proc model data=sashelp.citimon;
   endogenous eegp eec;
   exogenous exvus cciutc;
   parameters a1 a2 b1 b2 b3 ;
   label eegp   = 'Gasoline Retail Price'
         eec    = 'Energy Consumption'
         cciutc = 'Consumer Debt';

   /* -------- Supply equation ------------- */
   eq.supply = eec - (a1 + a2 * eegp );

   /* -------- Demand equation ------------- */
   eq.demand = eec - (b1 + b2 * eegp + b3 * cciutc);

   /* -------- Instrumental variables -------*/
   lageegp = lag(eegp); lag2eegp=lag2(eegp);

   /* -------- Estimate parameters --------- */
   fit supply demand / n3sls fsrsq;
   instruments _EXOG_ lageegp lag2eegp;
run;

title1 'Supply-Demand Model using General-form Equations';
proc model data=sashelp.citimon(where=(eec ne .));
   endogenous eegp eec;
   exogenous exvus cciutc;
   parameters a1 a2 a3 b1 b2 ;
   label eegp   = 'Gasoline Retail Price'
         eec    = 'Energy Consumption'
         cciutc = 'Consumer Debt';

   /* -------- Supply equation ------------- */
   eq.supply = eec - (a1 + a2 * eegp + a3 * cciutc);

   /* -------- Demand equation ------------- */
   eq.demand = eec - (b1 + b2 * eegp );

   /* -------- Instrumental variables -------*/
   lageegp = lag(eegp); lag2eegp=lag2(eegp);

   /* -------- Estimate parameters --------- */
   instruments _EXOG_ lageegp lag2eegp;
   fit supply demand / n3sls ;
   solve eegp eec / out=equilib;
run;

   title1;

title1 'Solving a Simultaneous System';
data test;
   input a b @@;
datalines;
  0 1   1 1   1 2
;

proc model data=test;
   eq.sqrt      = sqrt(x) - y;
   eq.hyperbola = a + b / x - y;
   solve x y / solveprint;
   id a b;
run;

title 'EXCHANGE Data';
data exchange ;
   input yr rate_jp rate_wg imn_jp imn_wg emp_us emp_jp emp_wg
            prod_us / prod_jp prod_wg cpi_us cpi_jp cpi_wg;
   im_jp = imn_jp/cpi_us;
   im_wg = imn_wg/cpi_us;
   ius = 100*(cpi_us-(lag(cpi_us)))/(lag(cpi_us));
   ijp = 100*(cpi_jp-(lag(cpi_jp)))/(lag(cpi_jp));
   iwg = 100*(cpi_wg-(lag(cpi_wg)))/(lag(cpi_wg));
   di_jp = ius - ijp;
   di_wg = ius - iwg;
datalines;
1974    .     .      .      .    .     .     .     .
        .     .   .493  .590  .672
1975 295.78 2.4613 11425  5410  93.0  99.8 103.3  93.5
      84.0  89.3  .538  .660  .712
1976 296.45 2.5184 15504  5592  96.4 100.8 100.8  97.1
      95.6  94.9  .569  .721  .742
1977 268.62 2.3236 18550  7238 100.0 100.0 100.0 100.0
     100.0 100.0  .606  .780  .769
1978 210.38 2.0096 24458  9962 104.2  98.9  99.4 100.9
     106.8 103.8  .652  .813  .790
1979 219.02 1.8342 26248 10955 107.1  98.1  99.8 101.5
     117.4 108.9  .726  .843  .823
1980 226.63 1.8175 30714 11693 103.3 101.3 100.4 101.7
     125.4 109.8  .824  .909  .868
1981 220.63 2.2631 37612 11379 102.8 102.2  97.9 104.6
     126.3 112.8  .909  .954  .922
1982 249.06 2.4280 37744 11975  95.8 101.4  95.0 107.1
     146.8 113.3  .965  .980  .970
1983 237.55 2.5539 41183 12695  94.4 103.4  91.1 111.6
     152.8 116.8  .996  .999 1.003
1984 237.45 2.8454 57135 16996  99.0 105.8  90.4 118.5
     152.2 124.7 1.039 1.021 1.027
1985 238.47 2.9419 68783 20239  98.1 107.6  91.3 124.2
     161.1 128.5 1.076 1.042 1.048
1986 168.35 2.1704 81911 25124  96.8 107.3  92.7 128.8
     163.8 130.7 1.096 1.049 1.047
1987 144.60 1.7981 84575 27069  97.1 106.1  92.8 132.0
     176.5 129.9 1.136 1.050 1.049
1988 128.17 1.7569 89802 26503  99.6 108.8  92.7 136.2
     190.0 135.9 1.183 1.057 1.063
;

          /* data for simulation */
data whatif;
   input yr rate_jp rate_wg imn_jp imn_wg emp_us emp_jp emp_wg
   prod_us / prod_jp prod_wg cpi_us cpi_jp cpi_wg;
   label cpi_us = 'US CPI 1982-1984 = 100'
         cpi_jp = 'JP CPI 1982-1984 = 100'
         cpi_wg = 'WG CPI 1982-1984 = 100';
   im_jp = imn_jp/cpi_us;
   im_wg = imn_wg/cpi_us;
   ius = 100*(cpi_us-(lag(cpi_us)))/(lag(cpi_us));
   ijp = 100*(cpi_jp-(lag(cpi_jp)))/(lag(cpi_jp));
   iwg = 100*(cpi_wg-(lag(cpi_wg)))/(lag(cpi_wg));
   di_jp = ius - ijp;
   di_wg = ius - iwg;
datalines;
1980 226.63 1.8175 30714 11693 103.3 101.3 100.4 101.7
     125.4 109.8  .824  .909  .868
1981 220.63 2.2631 35000 11000 102.8 102.2  97.9 104.6
     126.3 112.8  .909  .954  .922
1982 249.06 2.4280 40000 12000  95.8 101.4  95.0 107.1
     146.8 113.3  .965  .980  .970
1983 237.55 2.5539 45000 13100  94.4 103.4  91.1 111.6
     152.8 116.8  .996  .999 1.003
1984 237.45 2.8454 50000 14300  99.0 105.8  90.4 118.5
     152.2 124.7 1.039 1.021 1.027
1985 238.47 2.9419 55000 15600  98.1 107.6  91.3 124.2
     161.1 128.5 1.076 1.042 1.048
1986    .      .   60000 17000  96.8 107.3  92.7 128.8
     163.8 130.7 1.096 1.049 1.047
1987    .      .   65000 18500  97.1 106.1  92.8 132.0
     176.5 129.9 1.136 1.050 1.049
1988    .      .   70000 20000  99.6 108.8  92.7 136.2
     190.0 135.9 1.183 1.057 1.063
;

proc model data=exchange;
   endo im_jp im_wg;
   exo di_jp di_wg;
   parms a1 a2 b1 b2 c1 c2;
   label rate_jp = 'Exchange Rate of Yen/$'
         rate_wg = 'Exchange Rate of Gm/$'
         im_jp = 'Imports to US from Japan in 1984 $'
         im_wg = 'Imports to US from WG in 1984 $'
         di_jp = 'Difference in Inflation Rates US-JP'
         di_wg = 'Difference in Inflation Rates US-WG';

   rate_jp = a1 + b1*im_jp + c1*di_jp;
   rate_wg = a2 + b2*im_wg + c2*di_wg;

            /* Fit the EXCHANGE data */
   fit rate_jp rate_wg / sur outest=xch_est outcov outs=s;

            /* Solve using the WHATIF data set */
   solve rate_jp rate_wg / data=whatif estdata=xch_est sdata=s
          random=100 seed=123 out=monte forecast;
   id yr;
   range yr=1986;
run;

proc sort data=monte;
   by yr;
run;

proc univariate data=monte noprint;
   by yr;
   var rate_jp rate_wg;
   output out=bounds mean=mean p5=p5 p95=p95;
run;

title "Monte Carlo Generated Confidence Intervals on a Forecast";
proc sgplot data=bounds noautolegend;
  series x=yr y=mean / markers;
  series x=yr y=p5 / markers;
  series x=yr y=p95 / markers;
run;