Contents
AAE 637, Spring 2018, Assignment #2
2017 AK by Eduardo Cenci; 2018 updates by Adam Theising
% cd Z:\637\Assignment2 % Change as appropriate clear; % command to clear memory clc; % command to clear the command window clear global; % clear global variables from memory; [dat,txt] = xlsread('wool_assign_2_18','Wool Data'); % import data txt = horzcat('Year', txt); % clear previous log file and start it delete('question1.txt') ; diary('question1.txt'); % declare global variables global numobs numcol rhsvar depvar % replace missing values (zeroes) for NaN nonzero = ~any(dat(:,2:5)==0, 2); % find rows with no 0 value in future log vars dat = dat(nonzero,:); % delete rows with 0 in future log variables [numobs,numcol] = size(dat); % create log values (without "zero" issues) and other variables ln_Quant = log(dat(:,strcmp('Wool_Q',txt))); ln_PrWool = log(dat(:,strcmp('Wool_P',txt))); ln_PrSyn = log(dat(:,strcmp('Syn_P',txt))); ln_Time = log(dat(:,strcmp('Time',txt))); % create RHS matrix (x) and LHS vector (y) rhsvar = horzcat(ln_PrWool, ln_PrSyn, ln_Time); depvar = ln_Quant;
Question 1.i - perform estimations
clear nonzero ln_Quant ln_PrWool ln_PrSyn ln_Time; % define parameter names (constant is removed if intercept option == 0) pars = {'constant','ln_PrWool','ln_PrSyn','ln_Time'}; % call CRM_AR(1) function using option 0 for no intercept [b_gls,cov_gls,b_ols,cov_ols,rho,se_rho] = crm_ar1_proc(rhsvar,depvar,pars,1); % Note the Durbin-Watson statistics is 2.1704, with % respective p-value of 0.7925.
Number of observations: 45 Degrees of freedom: 41 Sum of Squared Errors (OLS): 4.1828 R-squared: 0.838 R-bar-squared: 0.826 Estimate of the error variance: 0.102 Table of Results - OLS ----------------------------------------------------------------- Variables Value Std.Err T-Value P-Value ----------------------------------------------------------------- constant 11.562739 1.710144 6.761266 0.000000 ln_PrWool -1.625973 0.116874 -13.912192 0.000000 ln_PrSyn 0.920834 0.199397 4.618091 0.000038 ln_Time -0.041515 0.055087 -0.753617 0.455385 ----------------------------------------------------------------- Estimated Inefficient Coefficient Variance-Covariance Matrix 2.9246 -0.0932 -0.2888 -0.0152 -0.0932 0.0137 -0.0015 -0.0004 -0.2888 -0.0015 0.0398 0.0013 -0.0152 -0.0004 0.0013 0.0030 Estimate of rho: -0.088003 Rho t-stat: -0.5860 Rho p-value: 0.5608 The Durbin-Watson statistic is: 2.1704 Sum of Squared Errors (FGLS): 4.1829 Table of Results - FGLS ----------------------------------------------------------------- Variables Value Std.Err T-Value P-Value ----------------------------------------------------------------- constant 11.510786 1.692446 6.801273 0.000000 ln_PrWool -1.624031 0.115350 -14.079098 0.000000 ln_PrSyn 0.926117 0.197875 4.680318 0.000031 ln_Time -0.042403 0.051069 -0.830307 0.411174 ----------------------------------------------------------------- Estimated Efficient Coefficient Variance-Covariance Matrix with AR(1) 2.8644 -0.0906 -0.2841 -0.0136 -0.0906 0.0133 -0.0015 -0.0004 -0.2841 -0.0015 0.0392 0.0012 -0.0136 -0.0004 0.0012 0.0026
Question 1.ii - own/cross price effects?
Are own and cross-price elasts respectively different from -1/1?
tneg1_b2 = (b_gls(2)+1)/sqrt(cov_gls(2,2)); tpos1_b3 = (b_gls(3)-1)/sqrt(cov_gls(3,3)); fprintf('\nT-stat for own-price elasticity = -1 is: %8.4f\n', ... tneg1_b2); fprintf('\nT-stat for cross-price elasticity = 1 is: %8.4f\n', ... tpos1_b3);
T-stat for own-price elasticity = -1 is: -5.4099 T-stat for cross-price elasticity = 1 is: -0.3734
Question 1.iii - are elasticities symmetric?
elast_own = - elast_cross = 0 == beta(1) + beta(2) = 0
theta = b_gls(2) + b_gls(3); var_theta = cov_gls(2,2) + cov_gls(3,3) + 2*cov_gls(2,3); tstat = theta/sqrt(var_theta); pvalue = 2*(1-tcdf(abs(tstat),numobs-2)); fprintf('\nThe t-stat for testing own elasticity = - cross elasticity is %8.4f (p-value = %5.4f)\n',... tstat, pvalue);
The t-stat for testing own elasticity = - cross elasticity is -3.1399 (p-value = 0.0031)
Question 2.i - Single grid search
clear previous variables and command window
clear b_gls b_ols cov_gls cov_ols covs pars psi pvalue se_gls se_ols se_rho ... rho theta tstat var_theta tneg1_b2 tpos1_b3 depvar rhsvar % clear previous log file and start it delete('question2.txt') diary('question2.txt'); % redefine RHS matrix (x) and LHS vector (y) x = dat(:,3:4); y = dat(:,2); % Set initial parameters for gridsearch beta_ini = horzcat(-1, -1); % beta_w, beta_s index = 500; increment = 0.05; [minsse,bgrid] = gridsearch(@wool_model_fn,x,y,beta_ini,increment,index); fprintf('min SSE: %8.3f\n', minsse); fprintf('beta_w: %8.3f\n', bgrid(1)); fprintf('beta_s: %8.3f\n', bgrid(2)); disp(' ');
Warning: File not found or permission denied Iteration #: 1 b1: 11.450 b2: 11.450 SSE Value: 4673147144667591000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000 Iteration #: 2 b1: 11.450 b2: 11.400 SSE Value: 2142444390184618100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000 Iteration #: 3 b1: 11.450 b2: 11.350 SSE Value: 982233010919209370000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000 Iteration #: 4 b1: 11.450 b2: 11.300 SSE Value: 450323300031610560000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000 Iteration #: 5 b1: 11.450 b2: 11.250 SSE Value: 206461603240137380000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000 Iteration #: 249996 b1: -13.500 b2: -13.300 SSE Value: 8675037.000 Iteration #: 249997 b1: -13.500 b2: -13.350 SSE Value: 8675037.000 Iteration #: 249998 b1: -13.500 b2: -13.400 SSE Value: 8675037.000 Iteration #: 249999 b1: -13.500 b2: -13.450 SSE Value: 8675037.000 Iteration #: 250000 b1: -13.500 b2: -13.500 SSE Value: 8675037.000 min SSE: 939746.661 beta_w: -0.850 beta_s: 1.650
Question 3. - adaptive grid search
beta_ini = horzcat(-1, -1); % inital guesses for beta_w, beta_s index = 500; increment = 0.05; [minsse,bgrid] = gridsearch2(@wool_model_fn,x,y,beta_ini,increment,index); disp(' '); fprintf('min SSE: %8.3f\n', minsse); fprintf('beta_w: %8.3f\n', bgrid(1)); fprintf('beta_s: %8.3f\n', bgrid(2)); disp(' ');
Adaptive iteration: 1 Step length: 0.050000 Min SSE: 939746.661 Adaptive iteration: 2 Step length: 0.025000 Min SSE: 939746.661 Adaptive iteration: 3 Step length: 0.012500 Min SSE: 939363.369 Adaptive iteration: 4 Step length: 0.006250 Min SSE: 929021.052 Adaptive iteration: 5 Step length: 0.003125 Min SSE: 928985.817 Adaptive iteration: 6 Step length: 0.001563 Min SSE: 928985.817 Adaptive iteration: 7 Step length: 0.000781 Min SSE: 928985.817 min SSE: 928985.817 beta_w: -0.850 beta_s: 1.655