Archive

Posts Tagged ‘programming’

Programming an estimation command in Stata: Writing a C plugin

This post is the second in a series that illustrates how to plug code written in another language (like C, C++, or Java) into Stata. This technique is known as writing a plugin or as writing a dynamic-link library (DLL) for Stata.

In this post, I write a plugin in C that implements the calculations performed by mymean_work() in mymean11.ado, discussed in Programming an estimation command in Stata: Preparing to write a plugin. I assume that you are familiar with the material in that post.

This is the 30th post in the series Programming an estimation command in Stata. See Programming an estimation command in Stata: A map to posted entries for a map to all the posts in this series. Read more…

Categories: Programming Tags:

Programming an estimation command in Stata: Preparing to write a plugin

This post is the first in a series that illustrates how to plug code written in another language (like C, C++, or Java) into Stata. This technique is known as writing a plugin or as writing a dynamic-link library (DLL) for Stata.

Plugins can be written for any task, including data management, graphical analysis, or statistical estimation. Per the theme of this series, I discuss plugins for estimation commands.

In this post, I discuss the tradeoffs of writing a plugin, and I discuss a simple program whose calculations I will replace with plugins in subsequent posts.

This is the 29th post in the series Programming an estimation command in Stata. See Programming an estimation command in Stata: A map to posted entries for a map to all the posts in this series. Read more…

Categories: Programming Tags:

Working with Java plugins (Part 2)

In my previous post, I talked about how to combine the Java library Twitter4J and Stata’s Java function Interface using Eclipse to create a helloWorld plugin. Now, I want to talk about how to call Twitter4j member functions to connect to Twitter REST API, return Twitter data, and load that data into Stata using the Stata SFI. Read more…

Categories: Programming Tags:

Working with Java plugins (Part 1)

Introduction

Three months ago, I wrote about a new command, twitter2stata, that imports data from Twitter’s REST API into Stata. Today, I will show you the tools we used to develop this command. Writing this command from scratch solely in Mata or ado-code would have taken several months. Fortunately, we can significantly speed up our development using an existing Java library (Twitter4J) and Stata’s Java plugins. In this post, I will discuss the basic steps of how to leverage a Java library and the Stata Java API.

Java is the most popular programming language in the world, so there are many libraries to support your development. A quick Google search should tell you if a Java library exists for what you are trying to do; this is how we found the library Twitter4J. For the rest of this blog entry, a basic understanding of programming in Java is helpful, but not necessary. Read more…

Categories: Programming Tags:

Programming an estimation command in Stata: Writing an estat postestimation command

estat commands display statistics after estimation. Many of these statistics are diagnostics or tests used to evaluate model specification. Some statistics are available after all estimation commands; others are command specific.

I illustrate how estat commands work and then show how to write a command-specific estat command for the mypoisson command that I have been developing.

This is the 28th post in the series Programming an estimation command in Stata. I recommend that you start at the beginning. See Programming an estimation command in Stata: A map to posted entries for a map to all the posts in this series. Read more…

Categories: Programming Tags:

Programming an estimation command in Stata: Consolidating your code


This is the 27th post in the series Programming an estimation command in Stata. I recommend that you start at the beginning. See Programming an estimation command in Stata: A map to posted entries for a map to all the posts in this series.

Ado-commands for ECM and PCM models

I now convert the examples of Read more…

Categories: Programming Tags:

Programming an estimation command in Stata: Nonlinear least-squares estimators


This is the 26th post in the series Programming an estimation command in Stata. I recommend that you start at the beginning. See Programming an estimation command in Stata: A map to posted entries for a map to all the posts in this series.

Gauss–Newton algorithm

Gauss–Newton algorithms frequently perform better than Read more…

Categories: Programming Tags:

Programming an estimation command in Stata: Certifying your command


This is the twenty-fifth post in the series Programming an estimation command in Stata. I recommend that you start at the beginning. See Programming an estimation command in Stata: A map to posted entries for a map to all the posts in this series.

Verification versus certification

Verification is the process of establishing Read more…

Categories: Programming Tags:

Programming an estimation command in Stata: Making predict work

I make predict work after mypoisson5 by writing an ado-command that computes the predictions and by having mypoisson5 store the name of this new ado-command in e(predict). The ado-command that computes predictions using the parameter estimates computed by ado-command mytest should be named mytest_p, by convention. In the next section, I discuss mypoisson5_p, which computes predictions after mypoisson5. In section Storing the name of the prediction command in e(predict), I show that storing the name mypoisson5_p in e(predict) requires only a one-line change to mypoisson4.ado, which I discussed in Programming an estimation command in Stata: Adding analytical derivatives to a poisson command using Mata.

This is the twenty-fourth post in the Read more…

Categories: Programming Tags:

Programming an estimation command in Stata: Adding analytical derivatives to a poisson command using Mata


This is the twenty-third post in the series Programming an estimation command in Stata. I recommend that you start at the beginning. See Programming an estimation command in Stata: A map to posted entries for a map to all the posts in this series.

Analytically computed derivatives for Poisson

The contribution of the i(th) observation to the log-likelihood function for the Poisson maximum-likelihood estimator is Read more…

Categories: Programming Tags: