Resources

A Translog Cost Function and Derived Demands

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

                    SAS Sample Library

        Name: modex21.sas
 Description: Example program from SAS/ETS User's Guide,
              The MODEL Procedure
       Title: A Translog Cost Function and Derived Demands
     Product: SAS/ETS Software
        Keys: derived demand, systems of equations
        PROC: MODEL
       Notes:

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

data klems;
   input year y k l e m s py pk pl pe pm ps vy vk vl ve vm vs;
datalines;
1949    26.5    67.1   179.3    50.1    39.2    26.4    43.8    23.7     9.4    17.1    21.8    13.6   6.978   1.047   3.271   0.198   2.279   0.183
1950    29.6      70   198.6    53.5    45.8    34.9      47    21.7      10    17.6    24.8    13.9   8.336   0.996   3.847   0.217    3.03   0.247
1951      30      72     192    54.5    48.7    36.5    52.9    30.3    10.1    16.6    29.6    14.7   9.506   1.432   3.743   0.208    3.85   0.272
1952    30.7    71.6   181.7    56.8    49.3    34.1    46.5    21.3    10.6    16.9    25.3    15.7   8.552   1.004   3.729   0.221   3.326   0.272
1953    31.5    69.3   180.4      56    52.7    35.2      45    18.1    11.1    18.1    23.3    16.6   8.495   0.824   3.853   0.234   3.287   0.297
1954      29    68.5   159.7    50.8    45.3      32      43     5.9    12.3    17.1    24.2      17    7.48   0.264   3.808     0.2    2.93   0.278
1955    32.7    68.1   167.9    56.4    52.7      37    43.2    19.9    11.3    16.7    23.8    17.5   8.461   0.889    3.67   0.217   3.355   0.329
1956    32.6    68.3   163.4    56.6    51.9    36.9      43    20.2    11.8    17.2    23.3    18.2   8.421   0.908   3.716   0.224   3.232   0.342
1957    31.8    67.1   152.5    53.2    49.1      37    42.8    18.6    12.3    17.8      24    18.7   8.165    0.82   3.633   0.218   3.142   0.353
1958    31.3    64.6   141.8      53    47.2    35.8    41.5    19.7    12.7    17.1      23    19.7    7.79   0.837    3.49   0.208   2.898   0.358
1959    34.6    63.4   152.1    55.8    53.4    34.7    42.4    25.1    13.2    16.8    23.2    20.1   8.794   1.047   3.875   0.216   3.301   0.355
1960    33.6    62.7   145.6    55.4    51.7    33.6      43    26.5    13.8      17    22.6    20.9   8.675   1.093   3.894   0.216   3.113   0.358
1961      35    62.1   141.9    55.5    54.2    32.5    41.8    26.2    13.9    16.9    22.9    21.5   8.774    1.07   3.823   0.216    3.31   0.355
1962    37.6    62.1   145.6    57.7    59.2    33.6    42.4    29.1    14.5    16.9    23.4    22.2   9.566   1.189   4.075   0.224     3.7   0.379
1963      39    62.5   143.4    60.1    62.8    34.1    42.3    30.6    14.9    16.4    23.2    22.8    9.89   1.256   4.115   0.228   3.896   0.395
1964    42.1    62.7   145.6    66.3    66.6    37.3    42.6    37.9    15.5    15.8    23.4    23.4   10.76   1.561   4.359   0.242   4.154   0.443
1965    45.4    64.5     154    69.2    67.9    38.1    42.8    43.8    16.1    15.6    23.7    24.1  11.656   1.858    4.78   0.248   4.302   0.467
1966      49    68.7   160.8      74    68.2    41.4    42.8    43.3    16.9    15.4    25.2    24.9  12.572   1.953   5.241   0.263    4.59   0.525
1967      50    72.3   156.5    81.4    67.9    47.1    42.3    37.7    17.9    15.5    25.3    25.6   12.68    1.79   5.405   0.292   4.581   0.613
1968      54    74.8   162.8    86.1    76.9      51    43.8    40.3    19.2    15.4    25.2    26.5  14.189   1.982   6.042   0.305   5.172   0.688
1969    56.2    77.3   161.9    87.8    77.9    54.4    44.1    40.8    20.5    15.8    25.4    27.5  14.867   2.071   6.421    0.32   5.293   0.762
1970      57    79.2   153.8    89.9    74.9    51.8    43.3    41.2    21.5    16.6    25.8      29    14.8   2.146   6.384   0.343   5.164   0.764
1971    60.2    81.5   153.1    94.6    81.3    57.2    43.2    37.6    22.8    18.4    25.7    30.4  15.591   2.011   6.728   0.401   5.566   0.885
1972    66.5    84.1   160.9   100.9    94.6    66.7    45.6    39.6    24.6      20    26.9    32.1  18.185    2.19   7.645   0.465   6.794   1.091
1973    65.7    87.4     162   102.1    90.5      65    50.5    36.2    27.4    22.8    31.3    33.7  19.896   2.081   8.588   0.537   7.574   1.115
1974    61.9    89.5   148.9    93.3    92.2      64    58.3    39.9    30.2    32.4    35.6    36.2  21.661   2.344   8.676   0.697   8.763    1.18
1975    60.6    89.7   133.4    93.2      84    65.8    56.3      36    31.5    40.2      36    39.1  20.468   2.124   8.109   0.863   8.062    1.31
1976    67.2    89.6   144.1    99.6    95.8    68.2    60.2    40.6    34.5    44.1    38.1    42.6  24.242   2.391    9.61   1.011   9.751   1.478
1977    73.8    90.3   143.8    98.7   100.6    73.4    61.6    51.4    37.4    50.2    40.8      46  27.261   3.052  10.382   1.143  10.968   1.716
1978      75    90.7   142.6    96.7    96.8    67.9    63.8    53.9    40.6    54.9    43.9    49.5  28.682   3.212   11.18   1.224  11.356    1.71
1979    76.4      90   139.6    93.4    94.1    67.4    67.3    53.6    44.1    62.8    50.1    53.1  30.828   3.169  11.894   1.352  12.591   1.821
1980    74.2    89.5   132.9      88    88.1    64.5    73.4    48.9    48.7    74.6    58.9    57.8  32.638   2.875    12.5   1.514  13.852   1.898
1981    73.1    89.5   127.7    85.4    86.6    58.1    80.4    52.5    53.1    87.1      67      63  35.246   3.089  13.102   1.715  15.478   1.862
1982    69.3    88.9   110.3    75.6    77.9    49.7    80.9    53.7    58.3   100.2    70.2    67.1  33.613   3.133  12.426   1.746  14.611   1.698
1983    78.3    88.7   117.4    81.7    89.5    56.7    82.3    68.1    61.2   105.6      70      71   38.62   3.969  13.881   1.987  16.736   2.047
1984    79.2    90.6   116.8    82.6    90.3    54.8    84.6    65.6    63.8   110.3    73.4      75   40.19   3.905  14.398   2.101  17.697   2.089
1985      77    90.8   109.9    79.5      87    53.2    84.3      64    65.9   107.8    73.4    78.2  38.931   3.818  13.983   1.974   17.04   2.117
1986    80.4    90.9   112.8      83    88.5    55.6      85    78.1    67.8    99.7    73.7    78.1  40.975   4.668  14.777   1.906  17.415   2.209
1987    86.5    91.1   119.1    91.3    95.1    61.2    86.8    77.4    71.1    97.9    76.6    81.6  45.052   4.633   16.35   2.059  19.468   2.542
1988    86.4    91.2   117.4    91.3      88    68.5    90.4      76    74.2    96.4    87.3    83.2   46.83   4.553  16.831   2.029  20.518   2.899
1989    88.3    91.5   115.5      92    90.7    77.9    92.3    70.5    78.6    99.4    89.7    83.2  48.895   4.238  17.526   2.106  21.725     3.3
1990    86.2      92   109.3    88.5    88.2    79.2    94.3    85.5    80.7    97.4    89.7    84.9  48.726   5.172  17.023   1.987  21.121   3.423
1991    85.8    92.1   107.6    90.5    86.6    84.2      95    89.3    82.4    95.4    89.5    85.6  48.884   5.406  17.134   1.989   20.69   3.664
1992    92.9    92.6   108.5    94.5    91.9    95.2    95.8   121.6    86.5      96    87.8    87.1  53.383   7.402  18.131   2.091  21.541   4.219
1993    97.6    93.9   109.8    98.8    97.4    98.3    95.6   110.6    89.8    97.9    89.9    90.2  55.964   6.819  19.041   2.229  23.364   4.512
1994   101.5    96.5   111.4   104.7   101.9   102.3    95.8    97.8    93.4    98.5    91.2    93.5  58.342   6.205  20.088   2.375  24.808   4.866
1995   100.5    98.8   105.7   106.2    99.7   102.7    98.8    88.8    96.5    94.4   100.7    96.3  59.593   5.765  19.701    2.31  26.782   5.035
1996     100     100     100     100     100     100     100     100     100     100     100     100  59.979   6.572  19.316   2.305  26.697   5.089
1997   100.7   101.8    99.7    95.9      99    97.2   100.4    98.8   102.4   101.8   101.7   104.2  60.601   6.605  19.713   2.248  26.879   5.155
1998    99.6   105.6    95.7    94.1   101.5    92.2     100    94.3   106.8    95.5    97.3   107.6  59.763   6.548  19.739    2.07  26.358   5.049
1999    96.9   106.9    88.5    91.7    93.7    85.2    97.4    86.3   113.1    97.2    97.3   110.6  56.602   6.061  19.337   2.054  24.354   4.796
2000    95.2   106.2    85.6    90.3    87.9    80.3    97.3      68   116.3   112.1   104.9   114.5  55.599   4.748  19.231   2.332  24.611   4.676
2001    85.3   103.5    74.5    81.1    76.3    68.3      97    71.5   118.5   115.4   105.5   117.3  49.627   4.865  17.042   2.156   21.49   4.074
;

data klems;
set klems;
   array values {5} vk vl ve vm vs;
   array costshares {5} sk sl se sm ss;
   cost = sum(vk,vl,ve,vm,vs);
   do i = 1 to 5;
      costshares{i} = values{i}/cost;
   end;
run;

data klems;
set klems;
label y="Output"
      k="Capital"
      l="Labor"
      e="Energy"
      m="Materials"
      s="Services"
      pk="Capital Price"
      pl="Labor Price"
      pe="Energy Price"
      pm="Materials Price"
      ps="Services Price"
      vk="Capital Value"
      vl="Labor Value"
      ve="Energy Value"
      vm="Materials Value"
      vs="Services Value"
      sk="Capital Share"
      sl="Labor Share"
      se="Energy Share"
      sm="Materials Share"
      ss="Services Share";
run;

proc sgplot data = klems;
   series x = year y = k / markers markerattrs =(symbol=circle);
   series x = year y = l / markers markerattrs =(symbol=square);
   series x = year y = e / markers markerattrs =(symbol=star);
   series x = year y = m / markers markerattrs =(symbol=diamond);
   series x = year y = s / markers markerattrs =(symbol=hash);
   title 'Factor Quantities';
   yaxis label = 'Quantity';
run;

proc sgplot data = klems;
   series x = year y = pk / markers markerattrs =(symbol=circle);
   series x = year y = pl / markers markerattrs =(symbol=square);
   series x = year y = pe / markers markerattrs =(symbol=star);
   series x = year y = pm / markers markerattrs =(symbol=diamond);
   series x = year y = ps / markers markerattrs =(symbol=hash);
   title 'Factor Prices';
   yaxis label = 'Price';
run;

proc sgplot data = klems;
   series x = year y = sk / markers markerattrs =(symbol=circle);
   series x = year y = sl / markers markerattrs =(symbol=square);
   series x = year y = se / markers markerattrs =(symbol=star);
   series x = year y = sm / markers markerattrs =(symbol=diamond);
   series x = year y = ss / markers markerattrs =(symbol=hash);
   title 'Factor Cost Shares';
   yaxis label = 'Cost Share';
run;

   goptions reset=title;

proc model data = klems;
   parameters a_k gkk gkl gke gkm gks gky
                 a_l glk gll gle glm gls gly
       a_e gek gel gee gem ges gey
       a_m gmk gml gme gmm gms gmy;
   endogenous sk sl se sm;
   exogenous pk pl pe pm ps y;

   /*System of Derived Demand Equations*/
   sk = a_k + gkk*log(pk) + gkl*log(pl) + gke*log(pe) + gkm*log(pm) + gks*log(ps)
            + gky*log(y);
   sl = a_l + glk*log(pk) + gll*log(pl) + gle*log(pe) + glm*log(pm) + gls*log(ps)
            + gly*log(y);
   se = a_e + gek*log(pk) + gel*log(pl) + gee*log(pe) + gem*log(pm) + ges*log(ps)
            + gey*log(y);
   sm = a_m + gmk*log(pk) + gml*log(pl) + gme*log(pe) + gmm*log(pm) + gms*log(ps)
            + gmy*log(y);

   fit sk sl se sm / itsur;

   label a_k = "SK Intercept"
         a_l = "SL Intercept"
         a_e = "SE Intercept"
         a_m = "SM Intercept"
         gkk = "SK K Price"
         gkl = "SK L Price"
         gke = "SK E Price"
         gkm = "SK M Price"
         gks = "SK S Price"
         gky = "SK Output"
         glk = "SL K Price"
         gll = "SL L Price"
         gle = "SL E Price"
         glm = "SL M Price"
         gls = "SL S Price"
         gly = "SL Output"
         gek = "SE K Price"
         gel = "SE L Price"
         gee = "SE E Price"
         gem = "SE M Price"
         ges = "SE S Price"
         gey = "SE Output"
         gmk = "SM K Price"
         gml = "SM L Price"
         gme = "SM E Price"
         gmm = "SM M Price"
         gms = "SM S Price"
         gmy = "SM Output";

   test "Homogeneity"
      gkk+gkl+gke+gkm+gks=0,
      glk+gll+gle+glm+gls=0,
      gek+gel+gee+gem+ges=0,
      gmk+gml+gme+gmm+gms=0, / lr;

   test "Symmetry"
      gkl=glk,
      gke=gek,
      gkm=gmk,
      glm=gml,
      gle=gel,
      gem=gme, / lr;

   test "Joint Homogeneity and Symmetry"
      gkk+gkl+gke+gkm+gks=0,
      glk+gll+gle+glm+gls=0,
      gek+gel+gee+gem+ges=0,
      gmk+gml+gme+gmm+gms=0,
      gkl=glk,
      gke=gek,
      gkm=gmk,
      glm=gml,
      gle=gel,
      gem=gme, / lr;
run;

proc model data = klems;
   parameters a_k gkk gkl gke gkm gks gky
              a_l glk gll gle glm gls gly
              a_e gek gel gee gem ges gey
              a_m gmk gml gme gmm gms gmy;
   endogenous sk sl se sm;
   exogenous pk pl pe pm ps y;
   restrict /*Homogeneity Restrictions*/
            gks+gkk+gkl+gke+gkm=0,
            gls+gkl+gll+gle+glm=0,
            ges+gke+gle+gee+gem=0,
            gms+gkm+glm+gem+gmm=0,
            /*Symmetry Restrictions*/
            gkl=glk, gke=gek, gkm=gmk, gle=gel, glm=gml, gem=gme;

   /*System of Derived Demand Equations*/
   sk = a_k + gkk*log(pk) + gkl*log(pl) + gke*log(pe) + gkm*log(pm) + gks*log(ps)
            + gky*log(y);
   sl = a_l + glk*log(pk) + gll*log(pl) + gle*log(pe) + glm*log(pm) + gls*log(ps)
            + gly*log(y);
   se = a_e + gek*log(pk) + gel*log(pl) + gee*log(pe) + gem*log(pm) + ges*log(ps)
            + gey*log(y);
   sm = a_m + gmk*log(pk) + gml*log(pl) + gme*log(pe) + gmm*log(pm) + gms*log(ps)
            + gmy*log(y);

   fit sk sl se sm / itsur chow = (24) outest=est;

   label a_k = "SK Intercept"
         a_l = "SL Intercept"
         a_e = "SE Intercept"
         a_m = "SM Intercept"
         gkk = "SK K Price"
         gkl = "SK L Price"
         gke = "SK E Price"
         gkm = "SK M Price"
         gks = "SK S Price"
         gky = "SK Output"
         glk = "SL K Price"
         gll = "SL L Price"
         gle = "SL E Price"
         glm = "SL M Price"
         gls = "SL S Price"
         gly = "SL Output"
         gek = "SE K Price"
         gel = "SE L Price"
         gee = "SE E Price"
         gem = "SE M Price"
         ges = "SE S Price"
         gey = "SE Output"
         gmk = "SM K Price"
         gml = "SM L Price"
         gme = "SM E Price"
         gmm = "SM M Price"
         gms = "SM S Price"
         gmy = "SM Output";

   test "Constant Returns to Scale"
      gky=0,
      gly=0,
      gey=0,
      gmy=0, / lr;
run;


proc means data = klems noprint mean;
   variables sk sl se sm ss;
   output out = meanshares mean = sk sl se sm ss;
run;

proc iml;
   /*Read in parameter estimates*/
   use est;
   read all var {gkk gkl gke gkm gks};
   read all var {gll gle glm gls};
   read all var {gee gem ges};
   read all var {gmm gms};
   close est;

   /*Calculate S parameter based on homogeneity constraint*/
   gss=0-gks-gls-ges-gms;

   /*Read in mean cost shares and construct vector*/
   use meanshares;
   read all var {sk sl se sm ss};
   close meanshares;

   w = sk//sl//se//sm//ss;

  print w;

  /*Construct matrix of parameter estimates*/
  gij = (gkk||gkl||gke||gkm||gks)//
        (gkl||gll||gle||glm||gls)//
        (gke||gle||gee||gem||ges)//
        (gkm||glm||gem||gmm||gms)//
        (gks||gls||ges||gms||gss);

   print gij;

   nk=ncol(gij);
   mi = -1#I(nk);    /*Initialize negative identity matrix*/
   eos = j(nk,nk,0); /*Initialize Marshallian EOS Matrix*/
   mos = j(nk,nk,0); /*Initialize Morishima EOS Matrix*/
   ep  = j(nk,nk,0); /*Initialize Price EOD Matrix*/

   /*Calculate Marshallian EOS and Price EOD Matrices*/
   i=1;
   do i=1 to nk;
   j=1;
   do j=1 to nk;
       eos[i,j] = (gij[i,j]+w[i]#w[j]+mi[i,j]#w[i])/(w[i]#w[j]);
       ep[i,j] = w[j]#eos[i,j];
   end;
   end;

   /*Calculate Morishima EOS Matrix*/
   i=1;
   do i=1 to nk;
   j=1;
   do j=1 to nk;
      mos[i,j] = ep[i,j]-ep[j,j];
   end;
   end;

   /*Print Elasticity Matrices*/
   factors = {"Capital" "Labor" "Energy" "Materials" "Services"};
   print
      ep[label="Price Elasticities of Demand" rowname=factors colname=factors
         format=d7.3],
      eos[label="Hicks-Allen Elasticities of Substitution" rowname=factors colname=factors
          format=d7.3],
      mos[label="Morishima Elasticities of Substitution" rowname=factors colname=factors
          format=d7.3];

run;