Dear STATA users,
I'm estimating a disequilibrium model (e.g. Laffont and Garcia (1977)). It is made of three equations : demand equation (Dt), supply equation (St) and transaction equation (observed quantity: Qt = min(Dt, St)). This system of equations can be estimated using the maximum likelihood principle (e.g. Maddala and Nelson (1974)).
Please find attached the excerpts from Goldfeld, S.M. and R.E.Quandt (1978), Some Properties of the Simple Disequilibrium Model with Covariance, Economics Letters, 1, 343-346. It provides the two cases of likelihood functions that I'm trying to estimate.
My STATA program for the first case is presented below (simplified and short version). Later I will provide also the program for the second case if needed.
I don't get the simulated model coefficients which means there is an error. But I can't see it. This is my first experience with ML programming with STATA (the same model works well with SAS nlmixed procedure). I read the book "Maximum Likelihood estimation with stata" 4th edition.
If you are more experienced with ML programming with STATA, could you please write me some tips/suggestions to resolve the problem with my program?
Thank you in advance.
/* 1. Model simulation*/
clear
use "H:\mydata.dta", clear
keep in 1/10000
global vars_demand variableA
global vars_supply variableB
keep $vars_demand $vars_supply
matrix R=(1, .5 \ .5, 1)
drawnorm u1 u2, corr(R)
correlate u*
generate x1 = $vars_demand
generate x2 = $vars_supply
ge ydemand = .5 + .3*x1 + u1
ge ysupply = .5 - .2*x2 + u2
g yobserved=min(ydemand,ysupply)
global yobserved yobserved
global demand $vars_demand
global supply $vars_supply
/*2. ML model estimation*/
set more off
capture program drop disequi_lf0
program disequi_lf0
version 12
args todo b lnf
tempvar y_demand y_supply sigmad sigmas sigma_d sigma_s v1 v2 f_d p_d f_s p_s
mleval `y_demand'=`b', eq(1)
mleval `sigmad'=`b', eq(2) scalar
mleval `y_supply'=`b', eq(3)
mleval `sigmas'=`b', eq(4) scalar
gen double `sigma_d'=exp(`sigmad')
gen double `sigma_s'=exp(`sigmas')
gen double `v1'=($ML_y2-`y_supply')/`sigma_s'
gen double `v2'=($ML_y1-`y_demand')/`sigma_d'
gen double `f_d'=normalden($ML_y1,`y_demand',`sigma_d')
gen double `p_d' = 1-normal(`v1')
gen double `f_s' = normalden($ML_y2,`y_supply',`sigma_s')
gen double `p_s' = 1-normal(`v2')
quietly {
replace `lnf'=ln(`f_d'*`p_d'+`f_s'*`p_s')
}
end
ml model lf0 disequi_lf0 (demand: $yobserved= $demand) (sigma_d: ) (supply: $yobserved= $supply) (sigma_s: )
ml check
ml search
ml max
I'm estimating a disequilibrium model (e.g. Laffont and Garcia (1977)). It is made of three equations : demand equation (Dt), supply equation (St) and transaction equation (observed quantity: Qt = min(Dt, St)). This system of equations can be estimated using the maximum likelihood principle (e.g. Maddala and Nelson (1974)).
Please find attached the excerpts from Goldfeld, S.M. and R.E.Quandt (1978), Some Properties of the Simple Disequilibrium Model with Covariance, Economics Letters, 1, 343-346. It provides the two cases of likelihood functions that I'm trying to estimate.
My STATA program for the first case is presented below (simplified and short version). Later I will provide also the program for the second case if needed.
I don't get the simulated model coefficients which means there is an error. But I can't see it. This is my first experience with ML programming with STATA (the same model works well with SAS nlmixed procedure). I read the book "Maximum Likelihood estimation with stata" 4th edition.
If you are more experienced with ML programming with STATA, could you please write me some tips/suggestions to resolve the problem with my program?
Thank you in advance.
/* 1. Model simulation*/
clear
use "H:\mydata.dta", clear
keep in 1/10000
global vars_demand variableA
global vars_supply variableB
keep $vars_demand $vars_supply
matrix R=(1, .5 \ .5, 1)
drawnorm u1 u2, corr(R)
correlate u*
generate x1 = $vars_demand
generate x2 = $vars_supply
ge ydemand = .5 + .3*x1 + u1
ge ysupply = .5 - .2*x2 + u2
g yobserved=min(ydemand,ysupply)
global yobserved yobserved
global demand $vars_demand
global supply $vars_supply
/*2. ML model estimation*/
set more off
capture program drop disequi_lf0
program disequi_lf0
version 12
args todo b lnf
tempvar y_demand y_supply sigmad sigmas sigma_d sigma_s v1 v2 f_d p_d f_s p_s
mleval `y_demand'=`b', eq(1)
mleval `sigmad'=`b', eq(2) scalar
mleval `y_supply'=`b', eq(3)
mleval `sigmas'=`b', eq(4) scalar
gen double `sigma_d'=exp(`sigmad')
gen double `sigma_s'=exp(`sigmas')
gen double `v1'=($ML_y2-`y_supply')/`sigma_s'
gen double `v2'=($ML_y1-`y_demand')/`sigma_d'
gen double `f_d'=normalden($ML_y1,`y_demand',`sigma_d')
gen double `p_d' = 1-normal(`v1')
gen double `f_s' = normalden($ML_y2,`y_supply',`sigma_s')
gen double `p_s' = 1-normal(`v2')
quietly {
replace `lnf'=ln(`f_d'*`p_d'+`f_s'*`p_s')
}
end
ml model lf0 disequi_lf0 (demand: $yobserved= $demand) (sigma_d: ) (supply: $yobserved= $supply) (sigma_s: )
ml check
ml search
ml max
Comment