Example: marketing

Dynare & Bayesian Estimation - Wouter den Haan

Dynare & Bayesian EstimationWouter J. Den HaanLondon School of Economicsc 2011 by Wouter J. Den HaanAugust 19, 2011 OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesOverview of the program Calculate likelihood,L(YTj ) Calculate posterior,P( jYT)_L(YTj )P( ) Calculate mode Calculate preliminary info about posterior using quick and dirty assumption of normality Use MCMC to trace the shape ofP( jYT) calculate things like con dence intervals Plot graphsOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesCalculate Likelihood as function of psi Given , get rst-order approximation of the model Write the system in state-space notation Use the Kalman lter to back out yt=yt bEhytjYt 1, x1iand y,t ytvector withnyobserved values bE ytjYt 1, x1 prediction according to Kalman lter yt:prediction error yt:function ofallthe shocks in the model Linearity=) yt N(0, y,t) likelihood of sequence can be calculatedOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesCalculate posterior & modeP( jYT)_L(YTj )P( ) P( jYT)is a complex function But its value can be calculated easily for given =)value of that attains the max can be calculated using anoptimization routine(in practice, max ofP( jYT)much easier to nd than max ofL(YTj )becaus

Dynare & Bayesian Estimation Wouter J. Den Haan London School of Economics c 2011 by Wouter J. Den Haan August 19, 2011

Tags:

  Estimation, Bayesian, Dynare amp bayesian estimation, Dynare

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Dynare & Bayesian Estimation - Wouter den Haan

1 Dynare & Bayesian EstimationWouter J. Den HaanLondon School of Economicsc 2011 by Wouter J. Den HaanAugust 19, 2011 OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesOverview of the program Calculate likelihood,L(YTj ) Calculate posterior,P( jYT)_L(YTj )P( ) Calculate mode Calculate preliminary info about posterior using quick and dirty assumption of normality Use MCMC to trace the shape ofP( jYT) calculate things like con dence intervals Plot graphsOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesCalculate Likelihood as function of psi Given , get rst-order approximation of the model Write the system in state-space notation Use the Kalman lter to back out yt=yt bEhytjYt 1, x1iand y,t ytvector withnyobserved values bE ytjYt 1, x1 prediction according to Kalman lter yt:prediction error yt:function ofallthe shocks in the model Linearity=) yt N(0, y,t) likelihood of sequence can be calculatedOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesCalculate posterior & modeP( jYT)_L(YTj )P( ) P( jYT)is a complex function But its value can be calculated easily for given =)value of that attains the max can be calculated using anoptimization routine(in practice, max ofP( jYT)much easier to nd than max ofL(YTj )becauseP( )makes problem better behaved)OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesInformation about posterior using MCMC But we want to calculate objects likeE[g( )]=Rg( )P( jYT)d RP( jYT)d Examples, mean, standard errors, con dence intervalsthese are all integralsOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesIdea behing MCMC Problem.

2 We cannot draw numbers directly fromP( jYT) Solution: Generatea sequencefor such that its distributionis equal toP( jYT)Implementing MCMC is not trivial!!!OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPart I:initialization// lc, lk, lz, ly;varexo e;parameters beta, rho, alpha, nu, delta;OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPart II:set values for parameters that arenot estimatedalpha = ;rho = ;beta = ;nu = 1;delta = ; Values will be ignored during Estimation So only needed if you rst give Dynare commands that requireparameter valuesOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPart III: modelmodel;exp(-nu*lc)=beta*(exp(-nu*lc( +1)))*(exp(lz(+1))*alpha*exp((alpha-1)*l k)+1-delta);exp(lc)+exp(lk)=exp(lz+alpha *lk(-1))+(1-delta)*exp(lk(-1));lz = rho*lz(-1)+e;end;OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPart IV (optional): analyze model solution& properties for speci ed parameter valuessteady;Stoch_simul(order=1,nocorr, nomoments,IRF=12); This requires having given numerical values forallparametersOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPart V: de ne priorsestimated_params;alpha, inv_gamma_pdf, , inf;end; more alternatives given belowOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPart V: initialize estimationTell Dynare what the observables arevarobs lk;OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPart V: initialize estimationGive initial values for steady stateinitval;lc = ;lk = ;lz = 0;end.

3 OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesCalculate steady stateSteady state must be calculated for many di erent values of !!! Linearize the system yourself then easy to solve for steady state Give the exact solution of steady state as initial values Provide program to calculate the steady state yourselfOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesCalculate steady state yourself If your *.mod le is called then write a Dynare checks whether a le with this name exists and will use it sequence of output should correspond with sequence given invar listOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesCalculate steady state yourselffunction [ys,check] = modela_steadystate(ys,exe)global M_beta = (1);rho = (2);alpha = (3);nu = (4);delta = (5);sig = (6);check = 0;z = 1;k = ((1-beta*(1-delta))/(alpha*beta))^(1/(al pha-1));c = k^alpha-delta*k;ys =[ c; k; z ];OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesHow to create this le?

4 In your *.mod le include:steady_state_model;z = 1;k = ((1-beta*(1-delta))/(alpha*beta))^(1/(al pha-1));c = k^alpha-delta*k;end;OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesWhen it has been created? Now that the le has been created you can do more things: solve for some analytically and some numericallyOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPart VI: EstimationActual Estimation command withsomeof the possible optionsestimation(datafile=kdata,mh_nblo cks=5,mh_replic=10000,mh_jscale=3,mh_ini t_scale=12) lk; lk:(optional) name of the endogenous variables ( if youwant to plot Bayesian IRFs) datafile: contains observables nobs: number of observations used (default all) first_obs: rst observation (default is rst)OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesMCMC options mh_replic: number of observations in each MCMC sequence mh_nblocks: number of MCMC sequences mh_jscale: variance of the jumps in in MCMC chain a higher value ofmh_jscale=)bigger steps through thedomain of & lower acceptance ratio acceptance ratio should be around (according tosomeoptimality results.

5 See below) mh_init_scale:variance of initial draw important to make sure that the di erent MCMC sequencesstart in di erent pointsOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPart VII: Using estimated modelAcutal Estimation command with some of the possible optionsshock_decomposition; plots graphs with the observables and the partexplained by which outputShocks versus modelTrendsThe big issuesPriors - formatestimated_params;parameter name, prior_shape, prior_mean,prior_standarddeviation[,prio r 3rd par. value, prior 4th par. value];endthe part in [] only for some priorsOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPriors - examplesalpha s prior is Normal with meanmuand standard deviationsigma:alpha , normal_pdf,mu,sigma;alpha s prior is uniform over[p3,p4]:alpha , uniform_pdf, ,,p3,p4;Note the two spaces betweeen the commasOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPriors - innovation variances use "stderr e" as the parameter name for the innovationvariance.

6 For example, stderr e , uniform_pdf, ,,p3,p4;Note the two empty spaces betweeen the commasOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPriors - examplesnamedistribution & parameters rangenormal_pdfN( , )Rgamma_pdfG2( , ,p3)[p3,+ )beta_pdfB( , ,p3,p4)[p3,p4]inv_gamma_pdfIG1( , )R+uniform_pdfU(p3,p4)[p3,p4]OverviewBas icsMCMCG enerated outputShocks versus modelTrendsThe big issuesPriors - gamma distributionP(x p3) =(x p3)k 1exp( (x p3)/ ) (k) k (k)=(k 1)!ifkis an integer (k)=Z 0tk 1e :shape parameter :scale parameter =k 2=k 2skewness=E(x p3)3/ Eh(x p3)2i 3/2=2/p mode:p3+ (k 1) fork 1 OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPriors - gamma distribution Ifk=1=)mode at lower bound Ifk=1=)exponential Ifk=degrees of freedom/2 en =2=)Chi-squared Gamma distribution is right-skewedOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPriors - gamma distribution (mean = 1) = outputShocks versus modelTrendsThe big issuesPriors - inverse gamma distribution- IfXhas a gamma(k, )=)1/Xhas an inverse gamma distribution( , 1/ )OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPriors - inverse gamma distributionP(x) =x k 1 kexp( /x) (k)k:shape parameter :scale parameter = /(k 1)fork>1 2= 2/ (k 1)2(k 2) fork>2skewness=4q(k 2)/(k 3)fork>3mode.]

7 /(k+1)OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPriors - beta distribution on [0,1]P(x) =x 1(1 x) 1B( , )B(k, ) = ( + ) ( ) ( ) :shape parameter :shape parameter = /( + ) 2= / ( + )2( + +1) skewness=2( )p + +1( + +2)p mode: 1 + 2for >1, >1 OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPriors - beta distribution If <1, <1=)U-shaped If >1, >1=)unimodal If <1, 1or =1, >1=)strictly decreasing If =1, >2=)strictly convex If =1,1< <2=)strictly concave If >1, 1or =1, <1=)strictly increasing If =1, >2=)strictly convex If =1,1< <2=)strictly concaveOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesPriors - beta distribution (mean = 2/5) = = outputShocks versus modelTrendsThe big issuesBrooks & Gelman 1989 statistics MCMC: should generate sequenceas ifdrawn fromP( jYT) Tough to check Minimum requirement is that distribution is same for di erent parts of the same sequence across sequences (if you have more than one)OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesBrooks & Gelman 1989 statistics ijtheithdraw (out ofI) in thejthsequence (out ofJ) jmean ofjthsequence mean across all available dataOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesBetween variancebB=1J 1J j=1 j 2 bBis an estimate of the variance of the mean ( 2/I)=)B=bBIis an estimate of the varianceOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesWithin variancebW=1JJ j=11II t=1 tj j 2W=1JJ j=11I 1I t=1 tj j 2 WandbWare estimates of the variance (averaged acrossstreams)

8 OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesWhat do we need?1 Between variance should go to zerolimI ! bB !02 Within variance should settle downlimI ! bW !constantOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesWhat do we needreported by Dynarered line:Wblue line:dVAR=bW+bBWe need1red and blue line to get close2red line to settle downOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesUnivariate extensions The above can be done for any moment, not just the variance Dynare reports three alternativesOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesMultivariate extension For each moment of interest you can calculate the multivariateversion covariance matrix for the variance these higher-dimensional objects have to be transformed intoscalar objects that can be plotted See.

9 Brooks and Gilman 1989 OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesAcceptance rate The MCMC chain has to cover the whole state space Roberts, Gelman, & Gilks (1997): optimal acceptance rate = Great but optimality is an asymptotic result (if dimension of ! ) optimality relies on assumption that elements of areindependent (or another assumption replacing this one).OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesWhat to watch while Dynare runsPlots here from two examples1As good as it gets: estimate only 1 parameter2 Estimate all parameters Both cases 5,000 observations No misspeci cation of the model , arti cial dataOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesWhat to watch while Dynare outputShocks versus modelTrendsThe big issuesWhat to watch while Dynare runs When Dynare gets to the MCMC part a window opens tellingyou in which MCMC run you are which fraction has been completed most importantlythe acceptance rate The acceptance rate should be "around" a relatively low acceptance rate makes it more likely that theMCMC travels through the whole domain of acceptance rate too high=)

10 Increasemh_jscaleOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesTables RESULTS FROM POSTERIOR MAXIMIZATION generated before MCMC part most important is the mode, the other stu is based onnormality assumptions which are typically not valid Estimation RESULTS (based on MCMC)OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesGraphs Prior MCMC diagnostics (see below) Prior & posterior densities Shocks implied at the mode Observable and corresponding implied valueOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesOutput for rst example Estimate only 1 parameter, standard deviation innovation correctly speci ed (neoclassical growth) model 5,000 observationsOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesUnivariate MCMC diagnostics 10-4SE_e (Interval)100020003000400050006000700080 00900010000468x 10-9SE_e (m2)100020003000400050006000700080009000 10000468x 10-13SE_e (m3)OverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big issuesMultivariate MCMC diagnostics outputShocks versus modelTrendsThe big issuesPosterior _eOverviewBasicsMCMCG enerated outputShocks versus modelTrendsThe big outputShocks versus modelTrendsThe big issuesObservables and implied outputShocks versus modelTrendsThe big issuesOutput for second example Esti


Related search queries