%David Agrawal %Economics 671 %Problem Set 10 Due Monday November 5, 2007 format('long','g'); close all; %closes all figures clc; %clears the screen clear; %clears the memory %1.a. %set the normal seed rand('seed',0); %Set Matrix Dim m=100; n=1; %Set Binomial Parameters %Bernoulli Draws, nbio=1 nbio=1; p=0.52; y=binornd(nbio,p,m,n); %1.b. Calculations Attached %MLE for Bernoulli is Phat = Xbar %note xbar = mean of p = .52 phat=mean(y); xbar=mean(y); %1.c. % Log Likelihood function. Note must place dot before matrix operators. %log likelihood function with p = r L=@(r) -m.*xbar.*log(r)-m.*(1-xbar).*log(1-r); %Plot L fplot(L,[0.001 .999]) %find the minimum of -L and calculate numerical phat starting search at .5 phatnum = fminsearch(L,.1) %solution is .52 %1.d. %give the first order condition dLdr = @(r) m.*xbar./r-m.*(1-xbar)./(1-r) phatnum2 = fsolve(dLdr,.5) %solution is .52 %note all solutions yield .52, which should be the case. The FOC, %minimization problem and the closed form solution should all eqaul .52