Documente Academic
Documente Profesional
Documente Cultură
Method of moments: Define the dummy variables dj = 1x=xj and the moment function
1 X
mj = dnj pnj
N n
where the fourth parameter follows from the adding-up criterion p4 = 1 pj6=4 . It is clear that
the MoM estimator equates the P theoretical first moments to the empirical moment are just the
empirical frequencies, so pj = n 1xn =xj .
b.
N jj = (1 pj )pj
N ij = pi pj
c
The estimates and standard errors are in Table (1). The Wald test gives a test statistic of 0.28. At
one degree of freedom, the p-value is about 60%.
Table 1:
Parameter Coefficient Std err
p1 0.1667 0.0481
p2 0.2000 0.0516
p3 0.1333 0.0439
1
2
a.
Let y be the true weight and y be the measured weight.
Given E[y |x = 0] = 180, the upper and lower bounds on E [y|y [100, 240], x = 0], call these
Econdl , Econdu are given by the upper and lower bounds of measurement errors on either side.
Multiplying through by the probabilities, the probability weighted contributions are (M el , M eu ) =
( 80 240 100 300
20 + 10 , 20 + 10 )
17
28 + Econdl = 180
20
17
35 + Econdu = 180
20
so (Econdl , Econdu ) = (170.59, 178.82). The true conditional expectation for y [80, 300] must lie
in the range of maximum measurement error
17 17
E [y|y [100, 240], x = 0] Econdl + M el , Econdu + M eu
20 20
= [173, 187]
b.
The sample median lies in the correctly measured range and the estimated median is therefore
unaffected by the measurement error, so M (y|x = 0) = 160.
c.
There is at least an issue an issue with significance and an issue with causality in the statement.
The statement refers to the difference in relative frequencies of vegetarian and non-vegetarian stu-
dents in the upper tail of the distribution P (y > 240|omnivore) P (y > 240|veggie) = 10
1
.
Firstly, since there are measurement errors, in the extreme, all omnivores true weight could be
epsilontically above 240 pounds, in which case the difference would not neither economically nor
statistically significant. It could also be that all omnivores were 300 pounds, that would certainly
be economically significant, possibly statistically significant, be we dont know given the informa-
tion.
Secondly, causality: is it the vegetarianism of the vegetarian students that hold their weight down
or are there any other habits correlated with vegetarianism, say an increased propensity of exer-
cise, eating disorders or whatever else that may bring your weight down. As far as we know, the
measurements dont tell.
a. & b.
The fixed effects were generated as
T 1
bi = ln 1 + x
bi + max xbit + i
30 5 t
2
for individuals I = 1, . . . , 25, for periods t = 1, . . . , T in b = 1, . . . , 1000 simulations, where
xbit iid U [0, 1] and i is an iid standard normal draw. For small T , there is then a cross-
sectional correlation between i and xi that motivates a fixed-effects estimator. Note that the
random component i of the fixed effect is kept constant within individual and across simulations.1
The latent variable y and the observed variable y are given by the process
yit = i + xit + it
(
1 if y > 0
y=
0 otherwise
where it is iid standard normal and xit is a scalar. The fixed effects and and the shocks
are unobserved. The fixed effects are not iid, so neither is {yit } conditional on x. The fixed
effects estimation problem can however be expressed in terms of a concentrated likelihood function
that will transform the problem to an iid structure and that also corresponds with the requested
optimisation algorithm. The iid error structure is also useful to check necessary conditions for
consistency. The log-likelihood function is
where f (yit |, ) = (i + xit )yit (1 (i + xit ))1yit is the common likelihood function for all
i, t. The ML criterion function is
1 XX
llT (, ) = ln(f (yit |, i ))
IT t i
corresponding to the algorithm. We can then express the estimation problem as a concentrated
log-likelihood problem. Holding I fixed, the log likelihood function can be written
1X
ll() E[ln(f (yi |, i ())] (2)
I
i
A necessary condition for consistency is that we can interchange the limit of the maximum (lhs
below), with the maximum of the limit (rhs below)
1X
plimT ln(f (yit |,
i ()) = E [ln (f (yi |,
i ())] for all i
T t
1
Some of you specified a process where each individual got a new draw for every period and most of you made
new draws for each simulation b. That ameliorates the estimation problem by averaging out the fixed effects across
individuals and increases the variation in y. Those who did got results that looked more like consistency for T = 200
than I report below. The reason is that the probability of the occasional likelihood problems at the tails of the fixed
effect distribution decreases when you redraw the fixed effect i for every t = 1, . . . , T . Then the effect is no longer
fixed and the consequence is less individual persistence.
2
In the sense that it leads to an estimator with equivalent asymptotic distribution.
3
for all , , where is a compact parameter set. Uniform convergence in probability of llT ()
to ll() is sufficient to ensure that. First, note that i is estimated using only the data for individ-
ual i conditional on . For fixed T , i will be estimated with some error. As with most non-linear
estimators, estimation errors lead to finite-sample bias. Since T stays fixed, the estimation errors
will persist even if I . The error of any i will then contaminate the estimate of in the outer
loop. This is the incidental parameters problem. When however T , the estimation error in
() goes to zero 3
for a known distribution function G(). Either Maximum Simulated Likelihood or a Bayesian
MCMC approach is generally required due to the inner integral. This approach might be
computationally burdensome, particularly as T .
The fixed effect i increases in T < 1000, changing the base rate E[P r(yi = 1)]. For some
individuals, the increase in the fixed effect leads to less variation in the outcome y. Less
variation in y may in turn frustrate the estimation of i . In the limit, if yi = 1 for all t, the
the ML estimator is not defined.
2 In our case, the expected value of i goes from on average of
E[i |T = 2] = 12 ln 1 + 15 + 15 = 0.16 to 1.96 for T = 2 and T > 1000, respectively, with the
4
average take over individuals. As T increases, then P r(y = 0) for most individuals become
a rarer event. Reduced variation in y for a given T makes the parameters more imprecisely
estimated. On the other hand, individuals with a low and negative individual specific fixed
effect i increase the variation in y as the constant grows.
To sum up a somewhat tldr discussion, we then have that
Though there is correlation between the regressor and the fixed effect for finite T , either
random or fixed effects are consistent estimators, yet biased in small samples.
3
Given the iid structure conditional on the fixed effects and assuming boundedness of the log likelihood function,
we get uniform convergence for the probit model. We can then apply Theorem 4.1.1 of Amemiya (1985) and we have
consistency.
4
Noting that the first component xt by LLN is 12 in expectation and that E[maxt xit ] is a first order statistic of
the standard uniform for N = 2 that is equal to 23 .
4
The variation in y changes with T < 1000 as the constant part of the fixed effect grows.
Though increasing T entails convergence to the true values, the true values themselves change,
and with it the base rate. The change in the variation in outcome y may decrease the
estimator precision more than the increased precision from more information, i.e. there may
not be convergence as T grows when T < 1000.
The distribution of for T = 2 and T = 30 is given in Figure (1). A plot of the means of
vs the
mean true value for each individual is given in Figure (2). The results below shows that for some
individuals, there are indeed computational problems due to little variation in y for large i even
for large T .
For T = 2, the distribution of is seen to have a large mass to the right of the true value 1
with a mean of 1.32, reflecting the fact that the fixed effects are biased and inconsistent in small T
samples. In Figure (2), I have plotted the true fixed effects vs the mean estimated effect over all
1000 simulations. The estimated fixed effects are noticeably biased away from zero.5
Increasing the time dimension to T = 30, the distribution of is seen to improve in Figure
(1). The mean is 1.03 displaying convergence to a symmetric distribution centered around the true
value.6 The true fixed effects are seen to have more mass on higher values for T = 30 in Figure
(2), reflecting the change in base rates as grows in T . Though the fixed effects are noticeably
less biased than for T = 2, the estimates still trail off as the variation in y decreases when i
gets far from 0. Particularly above i > 1, the estimates venture away on the positive side of the
true effects. This bias is a potential source of concern for fixed T as the substantial bias of some of
the estimates contaminates the estimates. A substantial bias in is seen to remain even for
relatively large T . The distribution of is still fairly well centered around zero as the bias in is
driven by a few very large outliers with hardly any variation in y where the optimiser is rewarded
for moving out of bounds to achieve a small increase in the fitted frequency.
Density
4
T=2
T = 30
3.5
2.5
Density
1.5
0.5
0
3 2 1 0 1 2 3 4 5 6 7
5
True vs estimated fixed effects
10
Estimated
T=2
T = 30
5
3 2 1 0 1 2 3
True
c.
As T goes to infinity, you can consistently estimate by either
1. Random effects.
2. Fixed effects.
3. Individual-by-individual.
listed in decreasing order of efficiency and increasing level of robustness to cross-sectional bias
contamination and distributional assumptions.
d.
The discussion above suggests we might want a consistent estimator that is robust to small sample
bias. Estimation individual-by-individual is consistent and avoids cross individual contamination
from the finite T bias we saw might still persist even for T = 200 for the is who have their base
rate sufficiently displaced by the increasing fixed effect. I also estimated an FE spec.
The resulting estimates yield the distributions of and in Figures (3) and (4).As expected,
the FE estimates have a tighter distribution than the I-by-I estimates due to the increased flexi-
bility of I-by-I. Predictably, as the constant increases with T , there are some individuals who get
outcome realisations of a series of y with hardly any variance at all. That shows up in the long tail
on the positive side of the distribution in Figure (3) (capped at 3) where the estimation routine
spins out. The fact that there are more observations does not counteract the reduction in variation
in outcome for some outlying individuals as the rare event effect dominates and cause estimation
problems. For most individuals, however, more observations reduces the bias. The distributions
are both centered around the true value. The mean and the median is 1 to more than eight
decimal places, an improvement from the bias for T = 30, where both the mean and the median
were larger than 1 by some hundredths.7
The means of are seen to align well with the true values for < 2, yet again, more biased
for larger . The fixed effects however trail off later this time, at about > 2 compared to about
> 1 for T = 30 and from abs() = 0 for T = 2. Eventually, as the common constant stops in-
7
The script runs for about 4 minutes.
6
creasing at T = 1000, the impact of extra information will override the rare event effect as T ,
yield variation in y and the estimator is consistent as T also for i > 2. There is hardly
any difference between the I-by-I spec and the FE so there is little cross-sectional contamination
in FE. The bias at large is again driven by mean being pushed out by some realisations of y
with barely any variation. This pushes the sample maximum far out in the parameter space for
some b and we get substantial bias. The median is for instance hardly affected as this happens rarely.
Finally, note that there is a curious dip in the discrepancy between the true and the estimated
at the far right hand side that is seemingly repeated for T = 2, 30 in Figure (2). Whether
the apparent pattern is a fluke or reflects some real statistical effect, I dont know, but running
the simulations a few times from different seeds, it appears not to be a strong pattern, if any at
all.
5
Density
0
0 0.5 1 1.5 2 2.5 3 3.5
a. & b
MSM can be used to estimate the distributions of offer and acceptance points. I use two theoretical
restrictions. Both distributions are truncated normal on [0,100] and since randomized matching
both is true and common knowledge, we can restrict the covariance between the offer and accep-
tance points to zero. There are then four parameters to estimate o , o2 for the offers and a , a2
for the acceptances.
7
True vs estimated fixed effects
10
Estimated
T= 200, Individual
T = 200, FE
T= 2, FE
T = 30, FE
5
3 2 1 0 1 2 3
True
Table 2:
Parameter Coeff. Std. Err.
1 22.00 0.06
2 17.96 0.55
12 10.04 0.17
22 40.22 4.53
8
Total computation time including 1000 bootstraps was about 23 minutes.
8
M604 Finals doit 31/03/2013 14:57
Contents
Final M604
1. MOM
3. Probit fixed effects
Plot density of estimates
Plot betas
Estimating individual per individual for T = 200
Density beta
Plot true vs estimated fixed effects
M604 Q4 ultimatum
Standard errors
Final M604
1. MOM
% Set parameters
N = 60;
% Moments
M = [m1 m2 m3] - repmat(p, N,1);
% Moment covariance
Sigma = -p'*p;
Sigma(eye(3)==1) = p.*(1-p);
Cov = 1/N*Sigma
% Wald test
R = [1 1 0];
r = 0.4;
file:///Users/Grace/Documents/MATLAB/M604%20CA/M604%20Final/html/M604%20Finals%20doit.html Page 1 of 8
M604 Finals doit 31/03/2013 14:57
clc
clear
rseed = 10;
% Set parameters
G = 25;
T = 200;
B = 1000;
% Estimation
options = ...
optimset('Display', 'notify', ...
'GradObj', 'On', ....
'LargeScale', 'Off', ...
'MaxFunEvals', 10000);
tic
parfor b = 1:B
% Reset start values and counter
alphanew = alphatrue(:,b);
betanew = 1;
thetanew = ones(G+1,1);
thetaold = zeros(G+1,1);
k = 0;
while abs(thetanew-thetaold) > 10^(-6)
% Update
alphaold = alphanew;
betaold = betanew;
thetaold = [alphanew; betanew];
% Set off iterated optimization run
[alphanew, ~, exitalpha] = fminunc(@(alpha) ...
m604finalprobit(alpha, betaold, y(:,:,b), X(:,:,b), 'alpha'), ...
alphaold, options);
[betanew, ~, exitbeta] = fminunc(@(beta) ...
m604finalprobit(alphanew, beta, y(:,:,b), X(:,:,b), 'beta'), ...
betaold, options);
thetanew = [alphanew; betanew];
file:///Users/Grace/Documents/MATLAB/M604%20CA/M604%20Final/html/M604%20Finals%20doit.html Page 2 of 8
M604 Finals doit 31/03/2013 14:57
disp('Convergence tracker:')
if sum(convergencetracker) == 0
disp('Proper exit')
elseif disp('Improper exit')
end
load ThetaT2.mat
alphaT2 = Theta(1:end-1,:);
alphatrueT2 = alphatrue;
betaT2 = Theta(end,:);
clear Theta alphatrue
load ThetaT30.mat
alphaT30 = Theta(1:end-1,:);
alphatrueT30 = alphatrue;
betaT30 = Theta(end,:);
clear Theta alphatrue
Plot betas
clf
hold on
plot(bT2xi, dbetaT2, '--k')
plot(bT30xi, dbetaT30,'k')
title('Density \beta', 'fontsize',12)
legend('T = 2', 'T = 30', 'Location', 'Best')
xlabel('\beta')
file:///Users/Grace/Documents/MATLAB/M604%20CA/M604%20Final/html/M604%20Finals%20doit.html Page 3 of 8
M604 Finals doit 31/03/2013 14:57
ylabel('Density')
print(gcf, '-dpdf','m604finalsbetadensity.pdf')
clc
clear
rseed = 10;
% Set parameters
G = 25;
T = 200;
B = 1000;
% Estimation
options = ...
optimset('Display', 'notify', ...
'GradObj', 'On', ....
'LargeScale', 'Off', ...
'MaxFunEvals', 10000, ...
'DerivativeCheck', 'off');
% Counter
k = 0;
Alpha = zeros(G,B);
Beta = zeros(G,B);
file:///Users/Grace/Documents/MATLAB/M604%20CA/M604%20Final/html/M604%20Finals%20doit.html Page 4 of 8
M604 Finals doit 31/03/2013 14:57
tic
parfor b = 1:B
% Reset start values and counter
alphanew = Alphatrue(:,b);
alphaold = zeros(G,1);
betanew = ones(G,1);
betaold = zeros(G,1);
thetanew = ones(2*G,1);
thetaold = zeros(2*G,1);
k = 0;
while abs(thetanew-thetaold) > 10^(-6)
% Update
alphaold = alphanew;
betaold = betanew;
thetaold = [alphanew; betanew];
% Set off iterated optimization run
[alphanew, ~, exitalpha] = fminunc(@(alpha) ...
m604finalprobit(alpha, betaold, y(:,:,b), X(:,:,b), 'alpha'), ...
alphaold, options);
[betanew, ~, exitbeta] = fminunc(@(beta) ...
m604finalprobit(alphanew, beta, y(:,:,b), X(:,:,b), 'beta'), ...
betaold, options);
thetanew = [alphanew; betanew];
% Break loop if iterate for too long
k = k+1;
if k > 100
break
end
% Keep track of undesirable exits
convergencecheck = ismember([exitalpha, exitbeta], [0,-1,-3]);
convergencetracker(b,1) = max(max(convergencecheck));
end
Alpha(:,b) = alphanew;
Beta(:,b) = betanew;
end
toc
disp('Convergence tracker:')
if sum(convergencetracker) == 0
disp('Proper exit')
elseif disp('Improper exit')
end
Density beta
load AlphaBeta.mat
load ThetaT2.mat
alphaT2 = Theta(1:end-1,:);
alphatrueT2 = alphatrue;
betaT2 = Theta(end,:);
clear Theta alphatrue
load ThetaT30.mat
alphaT30 = Theta(1:end-1,:);
file:///Users/Grace/Documents/MATLAB/M604%20CA/M604%20Final/html/M604%20Finals%20doit.html Page 5 of 8
M604 Finals doit 31/03/2013 14:57
alphatrueT30 = alphatrue;
betaT30 = Theta(end,:);
load ThetaT200.mat
alphaT200 = Theta(1:end-1,:);
alphatrueT200 = alphatrue;
betaT200 = Theta(end,:);
clear Theta alphatrue
betas= reshape(Beta,[G*B,1]);
disp('Mean and median of beta')
[mean(betas < 10) median(betas)]
clf
[betasIbI, betasIbIxi] = ksdensity(betas(betas<3));
[betasFE, betasFExi] = ksdensity(betaT200(betaT200<3));
clf
hold on
title('True vs estimated fixed effects', 'fontsize',12)
scatter(mean(Alphatrue,2), mean(Alpha,2),'o', 'k')
scatter(mean(alphatrueT200,2), mean(alphaT200,2),100,'d', 'k')
scatter(mean(alphatrueT2,2), mean(alphaT2,2),'filled', 'k')
scatter(mean(alphatrueT30,2), mean(alphaT30,2),'x', 'k')
xlabel('True \alpha')
ylabel('Estimated \alpha')
legend('T= 200, Individual', 'T = 200, FE','T= 2, FE', 'T = 30, FE', ...
'location', 'best')
plot([min(mean(alphatrueT30,2)), max(mean(alphatrueT30,2))], ...
[min(mean(alphatrueT30,2)),max(mean(alphatrueT30,2))],'k')
feffectsname = ['m604finalsalphatruevsestimatedT', num2str(T) '.pdf'];
print(gcf, '-dpdf', feffectsname)
hold off
M604 Q4 ultimatum
rng(101);
% Get data
load ultimatum.csv
offer = ultimatum(:,1);
file:///Users/Grace/Documents/MATLAB/M604%20CA/M604%20Final/html/M604%20Finals%20doit.html Page 6 of 8
M604 Finals doit 31/03/2013 14:57
accept = ultimatum(:,2);
terms=offer.*(accept>0);
% Set parameters
N = size(offer,1);
tic
[mom_estimates,~,exitflag] = fminsearch(@(z) ...
ultimatum_gmm(z,data_moments,paramdraws,matchdraws),...
thetastart, options);
toc
disp('Estimates')
mom_estimates
disp('Exit')
if ismember(exitflag,1) == 1
disp('Proper')
elseif disp('Improper')
end
Standard errors
% Nr of bootstraps
B = 1000;
% Resample pairs of the data, hold the simulation draws fixed. Re-estimate.
N = size(offer,1);
% Sample with replacement
sampler = randi(N,[N,B]);
% Pre-allocate
bestimates = zeros(B,4);
exitcheck = zeros(B,1);
tic
parfor b = 1:B
samplerb = sampler(:,b);
% Resample the data
data_momentsb = ultimatumdatamoments(data, samplerb);
file:///Users/Grace/Documents/MATLAB/M604%20CA/M604%20Final/html/M604%20Finals%20doit.html Page 7 of 8
M604 Finals doit 31/03/2013 14:57
% Estimates
[mom_estimatesb,~,exitflag] = fminsearch(@(z) ...
ultimatum_gmm(z,data_momentsb,paramdraws,matchdraws), ...
thetastart, options);
bestimates(b,:) = mom_estimatesb;
% Keep track of convergence.
exitcheck(b,1) = exitflag;
end
toc
% Results
disp('MSM estimates with bootstrapped errors')
[mom_estimates' std(bestimates)']
% Convergence check
disp('Exit')
if ne(sum(exitcheck),B) == 0
disp('Proper')
elseif ne(sum(exitcheck),B) == 1
disp('Improper')
end
file:///Users/Grace/Documents/MATLAB/M604%20CA/M604%20Final/html/M604%20Finals%20doit.html Page 8 of 8
m604finalprobit 28/03/2013 14:53
% Argument
theta = [alpha; beta];
v = (2*y-1).*(X*theta);
likh = normcdf(v);
% log-likelihood function
f = log(likh);
% Criterion
f = -sum(f);
% Set parameters
K = length(theta);
Kalpha = length(alpha);
% Gradient.
if strcmp('alpha', zig) == 1
% Set parameters
X = X(:,1:Kalpha);
% Gradient
g = repmat((2*y-1).*normpdf(v)./likh,1,Kalpha).*X;
g = -sum(g);
elseif strcmp('beta', zig) == 1
% Set parameters
X = X(:,Kalpha+1:end);
% Gradient
g = repmat((2*y-1).*normpdf(v)./likh,1,K-Kalpha).*X;
g = -sum(g);
end
file:///Users/Grace/Documents/MATLAB/M604%20CA/M604%20Final/html/m604finalprobit.html Page 1 of 1
m604finalprobitdata 28/03/2013 14:53
% Set seed
rng(rseed)
xbar = mean(x);
xbar = repmat(xbar,[T,1,1]);
xbar = reshape(xbar, [G*T,1,B]);
ups = randn([1,G,1]);
ups = repmat(ups, [T,1,B]);
ups = reshape(ups,[G*T,1,B]);
alphatrue = reshape(alpha,[T,G,B]);
alphatrue = mean(alphatrue,1);
alphatrue = reshape(alphatrue,[G,B]);
x = reshape(x, [G*T,1,B]);
% Choice variable
y = y>0;
file:///Users/Grace/Documents/MATLAB/M604%20CA/M604%20Final/html/m604finalprobitdata.html Page 1 of 1
ultimatum_gmm 28/03/2013 14:51
function f=ultimatum_gmm(trial_mu_sig,data_moments,paramdraws,matchdraws)
% M604 Finals: Ultimatum game MSM criterion.
% Add penalty on trial parameters venturing out of the domain to circumvent cumbersome cons
trained
% minimization routine.
if (min(trial_mu_sig)>0)
% Simulated moments
sim_moments(1)=mean(accept>0);
sim_moments(2)=mean(terms(accept>0));
sim_moments(3)=std(terms(accept>0));
sim_moments(4)=mean(offer(accept==0));
sim_moments(5)=std(offer(accept==0));
% Moment criterion
pre_f=sim_moments-data_moments;
f=pre_f*W*pre_f';
else
f=10^8 +min(trial_mu_sig)^2;
end
file:///Users/Grace/Documents/MATLAB/M604%20CA/M604%20Final/html/ultimatum_gmm.html Page 1 of 1
ultimatumdatamoments 28/03/2013 14:53
offerb = offer(sampler);
acceptb = accept(sampler);
termsb = terms(sampler);
% Bootstrap moments.
data_momentsb(1)=mean(acceptb>0);
data_momentsb(2)=mean(termsb(acceptb >0));
data_momentsb(3)=std(termsb(acceptb>0));
data_momentsb(4)=mean(offerb(acceptb==0));
data_momentsb(5)=std(offerb(acceptb==0));
f = data_momentsb;
file:///Users/Grace/Documents/MATLAB/M604%20CA/M604%20Final/html/ultimatumdatamoments.html Page 1 of 1