1 | initial version |

The following example may help you - adapted from Adkins(2009) as described below.

The command script (below) can be downloaded here: IVProbit.sha

The accompanying data is here: bank.shd

```
* SHAZAM - Instrumental Variables Probit Estimator by AGLS
*
* Produces Amemiya's Generalised Least Squares Estimator (AGLS)
*
* This estimator produces a consistent estimator of the standard errors and
* can therefore easily be used for subsequent hypothesis testing of the
* parameters.
*
* References:
*
* Amemiya, T., 1978, The estimation of a simultaneous equation generalized
* probit model, Econometrica 46, 1193-1205.
* Amemiya, T., 1981, Qualitative response models: a survey, Journal of
* Economic Literature 19, 1483-1536.
* Newey, W.K., 1987, Efficient estimation oflimited dependent variable
* models with endogenous explanatory variables,
* Journal of Econometrics 36, 231-250
*
* Translated from a program created and described by Lee C. Adkins in the
* paper:
* Adkins, L., 2009, An Instrumental Variables Probit Estimator using gretl
* Steps defined below are described in that paper.
* Newey(1987) also a good reference
*
* Variable definitions
* y2 = r.h.s. endogenous variables
* x = the complete set of instruments
* x1 = r.h.s. exogenous variables
* y1 = dichotomous l.h.s. variable
* Sample data is from Adkins(2009) to determine whether managerial incentives
* affect the use of foreign exchange derivatives by bank holding companies.
* Example replicates the results found in that paper.
*
* N.B. To reuse, set variables name_y2, name_x, name_x1, X,Y and X1 to
* your own example data
*
read(bank.shd) / names
genr const = 1
* Create character strings to list all the variables for interest
name_y2:eqrat bonus optval
name_x:const ltass linsown linstown roe mktbk perfor dealdum div dum97 dum98 dum99 dum00 no_emp no_subs no_off ceo_age gap cfa
name_x1:const ltass linsown linstown roe mktbk perfor dealdum div dum97 dum98 dum99 dum00
* Also set up some matrices with all the variables of interest
matrix X = const|ltass|linsown|linstown|roe|mktbk|perfor|dealdum|div|dum97|dum98|dum99|dum00|no_emp|no_subs|no_off|ceo_age|gap|cfa
gen1 kx = $cols
matrix Y = eqrat|bonus|optval
gen1 ky = $cols
matrix X1 = const|ltass|linsown|linstown|roe|mktbk|perfor|dealdum|div|dum97|dum98|dum99|dum00
*****************************************************************
* Before starting, disable irrelevant output
set nooutput
set noecho
set nodoecho
* Define equation matrices and useful parameters
matrix Z = X1|Y
matrix b = INV(X'X)*X'Y
matrix d = INV(X'X)*X'Z
gen1 s = ky
gen1 kx1 = kx+1
gen1 kxy = kx+ky
* Step 1: Regress each y variable and store resid / pred
do #=1,ky
* Select the regressand vector from the matrix using its index
matrix ycol = Y(0,#)
* Regress each y variable and store resid / pred
ols ycol [name_x] / resid=resid# pred=pred# noconstant
* Build up a list of the residual and predicted variable names to use later
name_res:[name_res] resid#
name_prd:[name_prd] pred#
endo
* Step 2: Perform RF probit, split and store coefficient and covariance arrays
probit d2 [name_x] [name_res] / noconstant coef=coeff cov=J
gen1 numcoeff = $K
* Split coefficient arrays
matrix alph = coeff
copy alph alpha / frow=1;kx trow=1;kx
copy alph lam / frow=kx1;numcoeff trow=1;s
* Convert J to matrix and store kx by kx submatrix
matrix JJ = J
copy JJ Jinv / frow=1;kx trow=1;kx fcol=1;kx tcol=1;kx
* Step 3: Calculate 2SIV estimator of equation
probit d2 x1 [name_res] [name_prd] / noconstant coef=coeff2
gen1 numcoeff = $K
matrix coeffm = coeff2
gen1 start=numcoeff-s+1
copy coeffm beta / frow=start;numcoeff trow=1;s
matrix rho = lam - beta
* Step 4: Calculate v2*inv(x'x)
matrix rhoY = Y * rho
ols rhoY x / noconstant cov=vcv
matrix v2 = vcv
matrix omega = (v2+Jinv)
* Step 5: Calculate covariance, std errors and delta
matrix cov = inv(d'*inv(omega)*d)
matrix se = sqrt(diag(cov))
matrix delt = cov*d'*inv(omega)*alpha
* Print results
set output
print delt se
```

2 | Added note |

The following example may help you - adapted from Adkins(2009) as described below.

The command script (below) can be downloaded here: IVProbit.sha

The accompanying data is here: bank.shd

```
* SHAZAM - Instrumental Variables Probit Estimator by AGLS
*
* Produces Amemiya's Generalised Least Squares Estimator (AGLS)
*
* This estimator produces a consistent estimator of the standard errors and
* can therefore easily be used for subsequent hypothesis testing of the
* parameters.
*
* References:
*
* Amemiya, T., 1978, The estimation of a simultaneous equation generalized
* probit model, Econometrica 46, 1193-1205.
* Amemiya, T., 1981, Qualitative response models: a survey, Journal of
* Economic Literature 19, 1483-1536.
* Newey, W.K., 1987, Efficient estimation oflimited dependent variable
* models with endogenous explanatory variables,
* Journal of Econometrics 36, 231-250
*
* Translated from a program created and described by Lee C. Adkins in the
* paper:
* Adkins, L., 2009, An Instrumental Variables Probit Estimator using gretl
* Steps defined below are described in that paper.
* Newey(1987) also a good reference
*
* Variable definitions
* y2 = r.h.s. endogenous variables
* x = the complete set of instruments
* x1 = r.h.s. exogenous variables
* y1 = dichotomous l.h.s. variable
* Sample data is from Adkins(2009) to determine whether managerial incentives
* affect the use of foreign exchange derivatives by bank holding companies.
* Example replicates the results found in that paper.
*
* N.B. To reuse, set variables name_y2, name_x, name_x1, X,Y and X1 to
* your own example data
*
read(bank.shd) / names
genr const = 1
* Create character strings to list all the variables for interest
name_y2:eqrat bonus optval
name_x:const ltass linsown linstown roe mktbk perfor dealdum div dum97 dum98 dum99 dum00 no_emp no_subs no_off ceo_age gap cfa
name_x1:const ltass linsown linstown roe mktbk perfor dealdum div dum97 dum98 dum99 dum00
* Also set up some matrices with all the variables of interest
matrix X = const|ltass|linsown|linstown|roe|mktbk|perfor|dealdum|div|dum97|dum98|dum99|dum00|no_emp|no_subs|no_off|ceo_age|gap|cfa
gen1 kx = $cols
matrix Y = eqrat|bonus|optval
gen1 ky = $cols
matrix X1 = const|ltass|linsown|linstown|roe|mktbk|perfor|dealdum|div|dum97|dum98|dum99|dum00
*****************************************************************
* Before starting, disable irrelevant output
set nooutput
set noecho
set nodoecho
* Define equation matrices and useful parameters
matrix Z = X1|Y
matrix b = INV(X'X)*X'Y
matrix d = INV(X'X)*X'Z
gen1 s = ky
gen1 kx1 = kx+1
gen1 kxy = kx+ky
* Step 1: Regress each y variable and store resid / pred
do #=1,ky
* Select the regressand vector from the matrix using its index
matrix ycol = Y(0,#)
* Regress each y variable and store resid / pred
ols ycol [name_x] / resid=resid# pred=pred# noconstant
* Build up a list of the residual and predicted variable names to use later
name_res:[name_res] resid#
name_prd:[name_prd] pred#
endo
* Step 2: Perform RF probit, split and store coefficient and covariance arrays
probit d2 [name_x] [name_res] / noconstant coef=coeff cov=J
gen1 numcoeff = $K
* Split coefficient arrays
matrix alph = coeff
copy alph alpha / frow=1;kx trow=1;kx
copy alph lam / frow=kx1;numcoeff trow=1;s
* Convert J to matrix and store kx by kx submatrix
matrix JJ = J
copy JJ Jinv / frow=1;kx trow=1;kx fcol=1;kx tcol=1;kx
* Step 3: Calculate 2SIV estimator of equation
probit d2 x1 [name_res] [name_prd] / noconstant coef=coeff2
gen1 numcoeff = $K
matrix coeffm = coeff2
gen1 start=numcoeff-s+1
copy coeffm beta / frow=start;numcoeff trow=1;s
matrix rho = lam - beta
* Step 4: Calculate v2*inv(x'x)
matrix rhoY = Y * rho
ols rhoY x / noconstant cov=vcv
matrix v2 = vcv
matrix omega = (v2+Jinv)
* Step 5: Calculate covariance, std errors and delta
matrix cov = inv(d'*inv(omega)*d)
matrix se = sqrt(diag(cov))
matrix delt = cov*d'*inv(omega)*alpha
* Print results
set output
print delt se
```

We leave the test for over identification to you.

3 | Created into a SHAZAM Proc, simplified |

The following example may help you - adapted from Adkins(2009) as described below.

The ~~command ~~example script ~~(below) ~~can be downloaded here: ~~IVProbit.sha~~IVProbit_Example.sha

The accompanying data is here: bank.shd

The SHAZAM Procedure can be downloaded here:IVProbit.prc

```
* Example calling Instrumental Variables Probit Procedure
*
* Sample data is from Adkins(2009) to determine whether managerial incentives
* affect the use of foreign exchange derivatives by bank holding companies.
* Example replicates the results found in that paper.
*
* N.B. To reuse, set variables X,Y, X1 and Y1 to your own problem
*
* Read the data and create a constant by hand
read(bank.shd) / names
genr const = 1
* Set up matrices with all the variables of interest
* y = r.h.s. endogenous variables
* x = the complete set of instruments
* x1 = r.h.s. exogenous variables
* y1 = dichotomous l.h.s. variable
matrix y = eqrat|bonus|optval
matrix x = const|ltass|linsown|linstown|roe|mktbk|perfor|dealdum|div|dum97|dum98|dum99|dum00|no_emp|no_subs|no_off|ceo_age|gap|cfa
matrix x1 = const|ltass|linsown|linstown|roe|mktbk|perfor|dealdum|div|dum97|dum98|dum99|dum00
matrix y1 = d2
* Disable irrelevant output
set nooutput
set noecho
set nodoecho
* Call the Proc
exec IVProbit
* Print results
set output
print delt se
```

The procedure IVProbit is below:

```
* SHAZAM Procedure - Instrumental Variables Probit Estimator by AGLS
*
* Produces Amemiya's Generalised Least Squares Estimator (AGLS)
*
* This
```~~estimator ~~procedure produces a consistent estimator of the standard errors and ~~
* ~~can therefore
* easily be used for subsequent hypothesis testing of the ~~
* ~~parameters.
*
* References:
*
* Amemiya, T., 1978, The estimation of a simultaneous equation generalized ~~
* ~~probit model, Econometrica 46, 1193-1205.
* Amemiya, T., 1981, Qualitative response models: a survey, Journal of ~~
* ~~Economic Literature 19, 1483-1536.
* Newey, W.K., 1987, Efficient estimation oflimited dependent variable ~~
* ~~models with endogenous explanatory variables, ~~
* ~~Journal of Econometrics 36, 231-250
*
* ~~Translated from ~~Based on a program created and described by Lee C. Adkins in the ~~
* paper:
~~paper
* Adkins, L., 2009, An Instrumental Variables Probit Estimator using gretl
* Steps defined below are described in that ~~paper.
* Newey(1987) ~~paper; Newey 1987 also a good reference
*
* ~~Variable definitions
* y2 ~~Definitions of required input variables to be declared in calling routine.
* y = r.h.s. endogenous variables
* x = the complete set of instruments
* x1 = r.h.s. exogenous variables
* y1 = dichotomous l.h.s. variable
~~
* Sample data is from Adkins(2009) to determine whether managerial incentives
* affect the use of foreign exchange derivatives by bank holding companies.
* Example replicates the results found in that paper.
*
* N.B. To reuse, set variables name_y2, name_x, name_x1, X,Y and X1 to
* your own example data
*
read(bank.shd) / names
genr const = 1
* Create character strings to list all the variables for interest
name_y2:eqrat bonus optval
name_x:const ltass linsown linstown roe mktbk perfor dealdum div dum97 dum98 dum99 dum00 no_emp no_subs no_off ceo_age gap cfa
name_x1:const ltass linsown linstown roe mktbk perfor dealdum div dum97 dum98 dum99 dum00
* Also set up some matrices with all the variables of interest
matrix X = const|ltass|linsown|linstown|roe|mktbk|perfor|dealdum|div|dum97|dum98|dum99|dum00|no_emp|no_subs|no_off|ceo_age|gap|cfa
gen1 kx = $cols
matrix Y = eqrat|bonus|optval
gen1 ky = $cols
matrix X1 = const|ltass|linsown|linstown|roe|mktbk|perfor|dealdum|div|dum97|dum98|dum99|dum00
*****************************************************************
* Before starting, disable irrelevant output
set nooutput
set noecho
set nodoecho
~~*
proc IVProbit
* Define equation matrices and useful parameters
matrix Z = X1|Y
gen1 nx=$rows
matrix b = INV(X'X)*X'Y
gen1 kx=$rows
gen1 ky=$cols
matrix d = INV(X'X)*X'Z
gen1 s = ky
gen1 kx1 = kx+1
gen1 kxy = kx+ky
* Step 1: Regress each y variable and store resid / pred
dim myres nx ky mypred nx ky
do #=1,ky
* Select the regressand vector from the matrix using its index
matrix ycol = ~~Y(0,#)
~~y(0,#)
* Regress each y variable on x and store resid / pred
ols ycol ~~[name_x] ~~x / resid=resid# pred=pred# noconstant
~~* Build up a list of the residual and predicted variable names to use later
name_res:[name_res] resid#
name_prd:[name_prd] pred#
~~copy resid# myres / frow=1;nx trow=1;nx fcol=1;1 tcol=#;#
copy pred# mypred / frow=1;nx trow=1;nx fcol=1;1 tcol=#;#
endo
* Step 2: Perform RF probit, split and store coefficient and covariance arrays
probit ~~d2 [name_x] [name_res] ~~y1 x myres / noconstant coef=coeff cov=J
gen1 numcoeff = ~~$K
* Split coefficient arrays
~~$k
matrix alph = coeff
copy alph alpha / frow=1;kx trow=1;kx
copy alph lam / frow=kx1;numcoeff trow=1;s
* Convert J to matrix and store kx by kx submatrix
matrix JJ = J
copy JJ Jinv / frow=1;kx trow=1;kx fcol=1;kx tcol=1;kx
* Step 3: Calculate 2SIV estimator of equation
probit ~~d2 ~~y1 x1 ~~[name_res] [name_prd] ~~myres mypred / noconstant coef=coeff2
gen1 numcoeff = $K
matrix coeffm = coeff2
gen1 start=numcoeff-s+1
copy coeffm beta / frow=start;numcoeff trow=1;s
matrix rho = lam - beta
* Step 4: Calculate v2*inv(x'x)
matrix rhoY = ~~Y ~~y * rho
ols rhoY x / noconstant cov=vcv
matrix v2 = vcv
matrix omega = (v2+Jinv)
* Step 5: Calculate covariance, std errors and delta
matrix cov = inv(d'*inv(omega)*d)
matrix se = sqrt(diag(cov))
matrix delt = cov*d'*inv(omega)*alpha
~~* Print results
set output
print delt se
~~procend

~~We leave the test for over identification ~~The easiest way to ~~you.~~use this is to download all 3 files listed at the top of this answer and place them in the same directory. Open the example into SHAZAM and click 'Run' or press F5.

4 | Formatting |

The following example may help you - adapted from Adkins(2009) as described below.

The example script can be downloaded here: IVProbit_Example.sha

The accompanying data is here: bank.shd

The SHAZAM Procedure can be downloaded here:IVProbit.prc

**EXAMPLE FILE**

```
* Example calling Instrumental Variables Probit Procedure
*
* Sample data is from Adkins(2009) to determine whether managerial incentives
* affect the use of foreign exchange derivatives by bank holding companies.
* Example replicates the results found in that paper.
*
* N.B. To reuse, set variables X,Y, X1 and Y1 to your own problem
*
* Read the data and create a constant by hand
read(bank.shd) / names
genr const = 1
* Set up matrices with all the variables of interest
* y = r.h.s. endogenous variables
* x = the complete set of instruments
* x1 = r.h.s. exogenous variables
* y1 = dichotomous l.h.s. variable
matrix y = eqrat|bonus|optval
matrix x = const|ltass|linsown|linstown|roe|mktbk|perfor|dealdum|div|dum97|dum98|dum99|dum00|no_emp|no_subs|no_off|ceo_age|gap|cfa
matrix x1 = const|ltass|linsown|linstown|roe|mktbk|perfor|dealdum|div|dum97|dum98|dum99|dum00
matrix y1 = d2
* Disable irrelevant output
set nooutput
set noecho
set nodoecho
* Call the Proc
exec IVProbit
* Print results
set output
print delt se
```

**SHAZAM PROCEDURE**

The procedure IVProbit is below:

```
* SHAZAM Procedure - Instrumental Variables Probit Estimator by AGLS
*
* Produces Amemiya's Generalised Least Squares Estimator (AGLS)
*
* This procedure produces a consistent estimator of the standard errors and can therefore
* easily be used for subsequent hypothesis testing of the parameters.
*
* References:
*
* Amemiya, T., 1978, The estimation of a simultaneous equation generalized probit model, Econometrica 46, 1193-1205.
* Amemiya, T., 1981, Qualitative response models: a survey, Journal of Economic Literature 19, 1483-1536.
* Newey, W.K., 1987, Efficient estimation oflimited dependent variable models with endogenous explanatory variables, Journal of Econometrics 36, 231-250
*
* Based on a program created and described by Lee C. Adkins in the paper
* Adkins, L., 2009, An Instrumental Variables Probit Estimator using gretl
* Steps defined below are described in that paper; Newey 1987 also a good reference
*
* Definitions of required input variables to be declared in calling routine.
* y = r.h.s. endogenous variables
* x = the complete set of instruments
* x1 = r.h.s. exogenous variables
* y1 = dichotomous l.h.s. variable
*
proc IVProbit
* Define equation matrices and useful parameters
matrix Z = X1|Y
gen1 nx=$rows
matrix b = INV(X'X)*X'Y
gen1 kx=$rows
gen1 ky=$cols
matrix d = INV(X'X)*X'Z
gen1 s = ky
gen1 kx1 = kx+1
gen1 kxy = kx+ky
* Step 1: Regress each y variable and store resid / pred
dim myres nx ky mypred nx ky
do #=1,ky
* Select the regressand vector from the matrix using its index
matrix ycol = y(0,#)
* Regress each y variable on x and store resid / pred
ols ycol x / resid=resid# pred=pred# noconstant
copy resid# myres / frow=1;nx trow=1;nx fcol=1;1 tcol=#;#
copy pred# mypred / frow=1;nx trow=1;nx fcol=1;1 tcol=#;#
endo
* Step 2: Perform RF probit, split and store coefficient and covariance arrays
probit y1 x myres / noconstant coef=coeff cov=J
gen1 numcoeff = $k
matrix alph = coeff
copy alph alpha / frow=1;kx trow=1;kx
copy alph lam / frow=kx1;numcoeff trow=1;s
* Convert J to matrix and store kx by kx submatrix
matrix JJ = J
copy JJ Jinv / frow=1;kx trow=1;kx fcol=1;kx tcol=1;kx
* Step 3: Calculate 2SIV estimator of equation
probit y1 x1 myres mypred / noconstant coef=coeff2
gen1 numcoeff = $K
matrix coeffm = coeff2
gen1 start=numcoeff-s+1
copy coeffm beta / frow=start;numcoeff trow=1;s
matrix rho = lam - beta
* Step 4: Calculate v2*inv(x'x)
matrix rhoY = y * rho
ols rhoY x / noconstant cov=vcv
matrix v2 = vcv
matrix omega = (v2+Jinv)
* Step 5: Calculate covariance, std errors and delta
matrix cov = inv(d'*inv(omega)*d)
matrix se = sqrt(diag(cov))
matrix delt = cov*d'*inv(omega)*alpha
procend
```

The easiest way to use this is to download all 3 files listed at the top of this answer and place them in the same directory. Open the example into SHAZAM and click 'Run' or press F5.

Copyright **SHAZAM Analytics, 2018** Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.