Skip to content

Commit

Permalink
(more) tweaks and updates for example scripts in Guide
Browse files Browse the repository at this point in the history
  • Loading branch information
AllinCottrell committed Feb 12, 2024
1 parent df32d2a commit ada6b81
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 76 deletions.
117 changes: 64 additions & 53 deletions doc/tex/dpanel.tex
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,11 @@ \subsection{Regressors}
dpanel 1 ; y const
\end{code}
In this case the default \texttt{dpanel} behavior, which agrees with
David Roodman's \texttt{xtabond2} for Stata \citep{Roodman2009}, is
to drop the constant (since differencing reduces it to nothing but
zeros). However, for compatibility with the DPD package for Ox, you
can give the option \verb|--dpdstyle|, in which case the constant is
retained (equivalent to including a linear trend in
David Roodman's \texttt{xtabond2} for Stata \citep{Roodman2009}, is to
drop the constant (since differencing reduces it to nothing but
zeros). However, for compatibility with the \app{DPD} package for
\app{Ox}, you can give the option \verb|--dpdstyle|, in which case the
constant is retained (equivalent to including a linear trend in
equation~\ref{eq:dpd-def}). A similar point applies to the
period-specific dummy variables which can be added in \texttt{dpanel}
via the \verb|--time-dummies| option: in the differences-only case
Expand Down Expand Up @@ -539,24 +539,29 @@ \section{Replication of DPD results}

The examples are based on the program files \texttt{abest1.ox},
\texttt{abest3.ox} and \texttt{bbest1.ox}. These are included in the
DPD package, along with the Arellano--Bond database files
\app{DPD} package, along with the Arellano--Bond database files
\texttt{abdata.bn7} and \texttt{abdata.in7}.\footnote{See
\url{http://www.doornik.com/download.html}.} The
Arellano--Bond data are also provided with gretl, in the file
\texttt{abdata.gdt}. In the following we do not show the output from
DPD or gretl; it is somewhat voluminous, and is easily generated by
the user. As of this writing the results from Ox/DPD and gretl are
identical in all relevant respects for all of the examples
shown.\footnote{To be specific, this is using Ox Console version 5.10,
version 1.24 of the DPD package, and gretl built from CVS as of
2010-10-23, all on Linux.}

A complete Ox/DPD program to generate the results of interest takes
this general form:

\begin{code}
\url{http://www.doornik.com/download.html}.} The Arellano--Bond data
are also provided with gretl, in the file \texttt{abdata.gdt}. In the
following we do not show the output from DPD or gretl; it is somewhat
voluminous, and is easily generated by the user. As of this writing
the results from Ox/DPD and gretl are identical in all relevant
respects for all of the examples shown.\footnote{To be specific, this
was last tested using Ox Console version 9.10, version 1.28 of the
DPD package, and gretl built from git as of 2024-02-12, all on
Linux.}

An Ox/DPD program to generate the results of interest takes the
general form shown in Listing~\ref{dpd-skeleton}. In the examples
below we take this template for granted and show just the
model-specific code.

\begin{script}
\caption{Template for Ox/DPD program}
\label{dpd-skeleton}
\begin{scode}
#include <oxstd.h>
#import <packages/dpd/dpd>
#import <packages/DPD/dpd>

main()
{
Expand All @@ -565,12 +570,13 @@ \section{Replication of DPD results}
dpd.Load("abdata.in7");
dpd.SetYear("YEAR");

// model-specific code here
// model-specific code goes here

delete dpd;
}
\end{code}
%
\end{scode}
\end{script}

In the examples below we take this template for granted and show just
the model-specific code.

Expand All @@ -595,17 +601,17 @@ \subsection{Example 1}

\begin{code}
dpd.SetOptions(FALSE); // don't use robust standard errors
dpd.Select(Y_VAR, {"n", 0, 2});
dpd.Select(X_VAR, {"w", 0, 1, "k", 0, 0, "ys", 0, 1});
dpd.Select(I_VAR, {"w", 0, 1, "k", 0, 0, "ys", 0, 1});
dpd.Select(DPD::Y_VAR, {"n", 0, 2});
dpd.Select(DPD::X_VAR, {"w", 0, 1, "k", 0, 0, "ys", 0, 1});
dpd.Select(DPD::I_VAR, {"w", 0, 1, "k", 0, 0, "ys", 0, 1});

dpd.Gmm("n", 2, 99);
dpd.SetDummies(D_CONSTANT + D_TIME);
dpd.SetDummies(DPD::D_CONSTANT + DPD::D_TIME);

print("\n\n***** Arellano & Bond (1991), Table 4 (b)");
dpd.SetMethod(M_1STEP);
dpd.SetMethod(DPD::M_1STEP);
dpd.Estimate();
dpd.SetMethod(M_2STEP);
dpd.SetMethod(DPD::M_2STEP);
dpd.Estimate();
\end{code}

Expand All @@ -631,8 +637,8 @@ \subsection{Example 1}

\subsection{Example 2}

The DPD file \texttt{abest3.ox} contains a variant of the above that
differs with regard to the choice of instruments: the variables
The \app{DPD} file \texttt{abest3.ox} contains a variant of the above
that differs with regard to the choice of instruments: the variables
\texttt{w} and \texttt{k} are now treated as predetermined, and are
instrumented GMM-style using the second and third lags of their
levels. This approximates column (c) of Table 4 in
Expand All @@ -642,18 +648,18 @@ \subsection{Example 2}
DPD and gretl with 2-step estimation:

\begin{code}
dpd.Select(Y_VAR, {"n", 0, 2});
dpd.Select(X_VAR, {"w", 0, 1, "k", 0, 0, "ys", 0, 1});
dpd.Select(I_VAR, {"ys", 0, 1});
dpd.SetDummies(D_CONSTANT + D_TIME);
dpd.Select(DPD::Y_VAR, {"n", 0, 2});
dpd.Select(DPD::X_VAR, {"w", 0, 1, "k", 0, 0, "ys", 0, 1});
dpd.Select(DPD::I_VAR, {"ys", 0, 1});
dpd.SetDummies(DPD::D_CONSTANT + DPD::D_TIME);

dpd.Gmm("n", 2, 99);
dpd.Gmm("w", 2, 3);
dpd.Gmm("k", 2, 3);

print("\n***** Arellano & Bond (1991), Table 4 (c)\n");
print(" (but using different instruments!!)\n");
dpd.SetMethod(M_2STEP);
dpd.SetMethod(DPD::M_2STEP);
dpd.Estimate();
\end{code}

Expand All @@ -674,31 +680,32 @@ \subsection{Example 2}

\subsection{Example 3}

Our third example replicates the DPD output from \texttt{bbest1.ox}:
this uses the same dataset as the previous examples but the model
specifications are based on \cite{blundell-bond98}, and involve
comparison of the GMM-DIF and GMM-SYS (``system'') estimators. The
basic specification is slightly simplified in that the variable
\texttt{ys} is not used and only one lag of the dependent variable
appears as a regressor. The Ox/DPD code is:
Our third example replicates the \app{DPD} output from
\texttt{bbest1.ox}: this uses the same dataset as the previous
examples but the model specifications are based on
\cite{blundell-bond98}, and involve comparison of the GMM-DIF and
GMM-SYS (``system'') estimators. The basic specification is slightly
simplified in that the variable \texttt{ys} is not used and only one
lag of the dependent variable appears as a regressor. The Ox/DPD code
is:

\begin{code}
dpd.Select(Y_VAR, {"n", 0, 1});
dpd.Select(X_VAR, {"w", 0, 1, "k", 0, 1});
dpd.SetDummies(D_CONSTANT + D_TIME);
dpd.Select(DPD::Y_VAR, {"n", 0, 1});
dpd.Select(DPD::X_VAR, {"w", 0, 1, "k", 0, 1});
dpd.SetDummies(DPD::D_CONSTANT + DPD::D_TIME);

print("\n\n***** Blundell & Bond (1998), Table 4: 1976-86 GMM-DIF");
dpd.Gmm("n", 2, 99);
dpd.Gmm("w", 2, 99);
dpd.Gmm("k", 2, 99);
dpd.SetMethod(M_2STEP);
dpd.SetMethod(DPD::M_2STEP);
dpd.Estimate();

print("\n\n***** Blundell & Bond (1998), Table 4: 1976-86 GMM-SYS");
dpd.GmmLevel("n", 1, 1);
dpd.GmmLevel("w", 1, 1);
dpd.GmmLevel("k", 1, 1);
dpd.SetMethod(M_2STEP);
dpd.SetMethod(DPD::M_2STEP);
dpd.Estimate();
\end{code}

Expand Down Expand Up @@ -832,9 +839,12 @@ \section{Cross-country growth example}
values dataset containing the data as transformed in the gretl script
shown above, using a missing-value code appropriate to the target
program.) For reference, the commands used with Stata are reproduced
below:
%
\begin{code}
in Listing~\ref{xtabond2-code}.

\begin{script}[htbp]
\caption{Stata commands for GDP growth example}
\label{xtabond2-code}
\begin{scode}
#delimit ;
insheet using CEL.csv
tsset unit time;
Expand All @@ -844,7 +854,8 @@ \section{Cross-country growth example}
gmm(lngd, lag(2 99)) rob nolev twostep;
xtabond2 ly L.ly linv lngd, gmm(L.ly, lag(1 99)) gmm(linv, lag(2 99))
gmm(lngd, lag(2 99)) rob nocons twostep;
\end{code}
\end{scode}
\end{script}

For the GMM-DIF model all three programs find 382 usable observations
and 30 instruments, and yield identical parameter estimates and
Expand Down
2 changes: 2 additions & 0 deletions doc/tex/functions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,8 @@ \subsection{Overloading}
endif
end function
set seed 12345
# call 1: x and y are scalars
eval x_plus_b_y(10, 3, 2)
Expand Down
46 changes: 23 additions & 23 deletions doc/tex/gretlOx.tex
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,13 @@ \section{\app{Ox} support in gretl}
\section{Illustration: replication of DPD model}
\label{sec:dpd-replication}

Listing~\ref{script:Ox-DPD} shows a more ambitious case. This script
Listing~\ref{ex:ox-dpd} shows a more ambitious case. This script
replicates one of the dynamic panel data models in
\cite{arellano-bond91}, first using gretl and then using \app{Ox}; we
then check the relative differences between the parameter estimates
produced by the two programs (which turn out to be reassuringly
small).
small). This was last tested using version 9.10 of \app{Ox console}
for Linux.

Unlike the previous example, in this case we pass the dataset from
gretl to \app{Ox} as a CSV file in order to preserve the
Expand All @@ -131,30 +132,29 @@ \section{Illustration: replication of DPD model}
gretl side. The \verb|gretl_export| function takes two arguments, a
matrix and a file name. The file is written into the user's dotdir,
from where it can be picked up using \texttt{mread}. The final
portion of the output from Listing~\ref{script:Ox-DPD} is shown below:
portion of the output from Listing~\ref{ex:ox-dpd} is shown below:
%
\begin{code}
? matrix oxparm = mread("oxparm.mat", 1)
Generated matrix oxparm
? eval abs((parm - oxparm) ./ oxparm)
1.4578e-13
3.5642e-13
5.0672e-15
1.6091e-13
8.9808e-15
2.0450e-14
1.0218e-13
2.1048e-13
9.5898e-15
1.8658e-14
2.1852e-14
2.9451e-13
1.9398e-13
1.1094e-12
1.6314e-12
1.7885e-13
1.1949e-12
1.8999e-13
1.1359e-13
6.5339e-13
3.1943e-12
1.2108e-12
3.7335e-13
1.7468e-12
3.9536e-12
2.0980e-12
\end{code}

\begin{script}[htbp]
\caption{Estimation of dynamic panel data model via gretl and \app{Ox}}
\label{script:Ox-DPD}
\scriptinfo{ox-dpd}{Estimation of dynamic panel data model via gretl and \app{Ox}}
\begin{scode}
open abdata.gdt

Expand All @@ -169,20 +169,20 @@ \section{Illustration: replication of DPD model}
# Replicate using the Ox DPD package
foreign language=Ox
#include <oxstd.h>
#import <packages/dpd/dpd>
#import <packages/DPD/dpd>
main ()
{
decl dpd = new DPD();
dpd.Load("@dotdir/abdata.csv");
dpd.SetYear("YEAR");
dpd.Select(Y_VAR, {"n", 0, 2});
dpd.Select(X_VAR, {"w", 0, 1, "k", 0, 0, "ys", 0, 1});
dpd.Select(I_VAR, {"w", 0, 1, "k", 0, 0, "ys", 0, 1});
dpd.Select(DPD::Y_VAR, {"n", 0, 2});
dpd.Select(DPD::X_VAR, {"w", 0, 1, "k", 0, 0, "ys", 0, 1});
dpd.Select(DPD::I_VAR, {"w", 0, 1, "k", 0, 0, "ys", 0, 1});
dpd.Gmm("n", 2, 99); // GMM-type instrument
dpd.SetDummies(D_CONSTANT + D_TIME);
dpd.SetDummies(DPD::D_CONSTANT + DPD::D_TIME);
dpd.SetTest(2, 2); // Sargan, AR 1-2 tests
dpd.Estimate(); // 1-step estimation
decl parm = dpd.GetPar();
Expand Down
5 changes: 5 additions & 0 deletions doc/tex/realtime.tex
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,11 @@ \subsection{An illustration}
The script that produced this Figure is shown in full in
Listing~\ref{ex:realtime-revisions}.

\tip{To replicate the examples in Listings \ref{ex:realtime-revisions}
and \ref{ex:revision-history} below you'll need the Alfred file
\texttt{INDPRO.txt}, which is available as
\url{https://gretl.sf.net/gretldata/INDPRO.txt}.}

\begin{figure}[htbp]
\centering
\includegraphics{figures/realtime}
Expand Down
1 change: 1 addition & 0 deletions doc/tex/tsfilter.tex
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ \section{The discrete Fourier transform}
\begin{scode}
set verbose off
nulldata 50
set seed 76543
# generate an AR(1) process
series e = normal()
series x = 0
Expand Down

0 comments on commit ada6b81

Please sign in to comment.