% Syntax 
%
% All values are in logarithms
%
% The INPUTS are:  
%
% Y - a (T*n)x1 vector of dependent variable
% X - a (T*n)xp matrix of independent variables
% n - number of cross sections
% g_para - Global parameters
% pss_para - parameters for PSS estimators
% kss_para - parameters for KSS estimators
% EST - model selection vector
% See below for details
%
% The OUTPUTS are:
%   
%  Parameter estimates
%  Standard errors
%  Average technical efficiency
%  Correlation of effects and efficiencies
%  Spearman rank order correlation of effects and efficiencies
% 
% 
clear all; close all;  st0=clock; warning off; clc; format short;


%************************************************
%                  Output File                  *
%************************************************

diary alpha.out;      % change the output filename 
                      % or comment out by placing '%' in front of the line 
		      %    if you don't want to save the results
diary off;

%************************************************
%                   Data Input                  *
%************************************************

choice=1;
                      % US limited-branch banks, annual data 1984-1995 

    if choice==0; load limann.asc;  data=limann;   clear limann;     % entire sample 
elseif choice==1; load limsmall.asc; data=limsmall;  clear limsmall;    % small size banks (0%~50%)
elseif choice==2; load limlarge.asc; data=limlarge;  clear limlarge;    % large size banks (50%~100%)
end;


y=data(:,1);        % y=real-estate loan
x=data(:,2:9);      % x1=commercial and industrial loan
                    % x2=installment loan
		    % x3=CD, x4=DD, x5=OD, x6=labor, x7=capital, x8=purf
		    % see KSS (2003) for data definition


[nt,p] = size(x);   % nt=total obs, p=number of regressors
     t = 12;        % number of time periods
     n = nt/t;      % number of banks

clear data;
  
%************************************************
%               Model Selection                 *
%************************************************

% 1=choose, 0=do not choose          

%***** Basic Panel Data Estimators *****

FR=2;                 % Fixed and Random Effects Estimators
                      % 1=Fixed, 2=Fixed and Random

HT=0;                 % Hausman-Taylor Estimator


%***** Semiparametric Efficient Estimators *****

PSS1=0;               % Some regressors are correlated with effects
PSS2=0;               % AR(1) error
PSS3=0;               % dynamic panel data model


%***** Time-varying Effects Estimators *****

CSS=0;                % Cornwell-Schmidt-Sickles Estimator
                      % 1=CSSW (Within), 2=CSSW and CSSG (Within and GLS)

KSS=0;                % Kneip-Sickles-Song Estimator
BC=0;                 % Battese-Coelli Estimator
DEA=0;                % Data Envelope Analysis Estimator



%************************************************
%              Global Parameters                *
%************************************************
  
   % truncation for outliers
   % remove top and bottom 5% of efficiencies

   trunc1 = 0.05;     % for the FR,HT,PSS123,CSS,KSS estimators
   trunc2 = 0.00;     % for the BC and DEA estimators

     tmtr = 0;        % include linear time trend to FR, HT, PSS123, BC

     p1 = p-1;        % number of uncorrelated variables in X for HT and PSS1 estimator
                      % uncorrelated variables come first

   % Figures
     fig1 = 0;        % Average of time-variant estimators
     fig2 = 0;        % Time-variant estimators
     fig3 = 0;        % Estimated efficiencies from each estimator

   % Tables
     tab1 = 0;        % Average of time-variant estimators
     tab2 = 0;        % Time-variant estimators
     tab3 = 0;        % Individual Effects from each estimator

  firmeff = 0;        % save efficiencies for each firm

  out_fig = [fig1 fig2 fig3];
  out_tab = [tab1 tab2 tab3];

   g_para = [trunc1 trunc2 tmtr out_fig out_tab firmeff];

%************************************************
%           Parameters for PSS estimators       *
%************************************************

                      % see PSS papers for details

                      % Bandwidth selection by bootstrapping
     NB = 5;          % number of bootstrap repetiton
  gr_st = 0.1;        % starting point of grid search
  gr_in = 0.1;        % increment of grid search
  gr_en = 0.1;        % end point of grid search

pss_out = 1;          % output print option, 1 = print, else = skip print

 pss_para = [NB gr_st gr_in gr_en pss_out p1];


%************************************************
%           Parameters for KSS estimators       *
%************************************************

                      % see KSS (2003) for details

    LS = 8;           % maximum dimension choice

                      % bandwidth selection 
 gr_st = 0.1;         % starting point of grid search
 gr_in = 0.1;         % increment of grid search
 gr_en = 0.6;         % end point of grid search

   kss_para = [LS gr_st gr_in gr_en];

%************************************************
%      Please do not modify the part below      * 
%************************************************


%************************************************
%                  Estimation                   * 
%************************************************

EST= [FR HT PSS1 PSS2 PSS3 CSS KSS BC DEA];


% estimation procedure

estm(y,x,n,g_para,pss_para,kss_para,EST);  

disp(sprintf('* Elapsed Time (minutes): %5.3f',etime(clock,st0)/60))

