UN Comtrade API in Stata

The UN Comtrade is the largest repository of disaggregated trade statistics. It offers free access to detailed annual trade data starting from 1962 and monthly trade data from 2010. Free access is limited to 50,000 records per query. This limitation is relaxed in some cases but the API (as of date) only allows a maximum of 50,000 records per query for all users.

The UN Comtrade data extraction API (currently beta version) to access the database is publicly available. How can we exploit this to download Comtrade data directly from Stata?
Continue reading

Where to buy Stata in the Philippines

In the Philippines, there has been an emerging demand in the public sector for data-driven analysis of various govenrment programs (yes, emerging.. don’t ask why.. but the leadership has a lot to do with this.. bless them). I am lucky enough to be invited to introduce Stata to some government agencies (and some private institutions) and how it can be used with their data. Often the the question where to get a copy of Stata pops up. So, for reference: here is the sole distributor of Stata in the country:

Continue reading

Statalist, too, has a new home

If you have been following Statalist (see Stuck? Hello Statalist), the email-based support system for Stata users, you must have long known that it has moved to a new home and a new format. Statalist is now a forum hosted at Stalist.org maintained by StataCorp but moderated by a “friendly group” (quoted from the site) of users.

…a forum where Stata users from experts to neophytes maintain a lively dialogue about all things statistical and Stata…

Everyone can browse through the forum but only registered users may participate in the discussions. You may register here. DON’T forget to read the FAQ before posting.

PS They really are nice people until you piss them off 😉



Links: Introduction to Stata

  1. Baum, Schaffer, and Stillman answer the question “What is Stata, and why should it be the package of choice for applied econometric research?” in “Using Stata for Applied Research: Reviewing its Capabilities”.

2. UCLA’s Stata resources and UCLA’s Stata class notes with accompanying videos. Learning Stata made easier…

  1. This site by German Rodriguez provides an introduction to Stata with emphasis on data management and graphics.

  2. Here is a link to a 42-page introduction to Stata—from basics to Mata—by Austin Nichols (2007).

  3. Following the examples on this page is helpful for those who want to learn the basics of Stata graphics

Can’t get enough of factor variables

In relation to yesterday’s blog post, here are three links to useful sites/files that provide very good introduction to Stata’s factor variables:

Christopher Baum’s Factor Variables and Marginal Effects in Stata 11

Michael Mitchell’s Stata Tidbit of the Week – What the ##?

UCLA ATS’s What’s new in Stata 11: Factor variables, margins and interactions

What Stata books are in the libraries of top Philippine universities?

Curious, I searched through the online catalogs of the top universities in the Philippines to find an answer. What I found is a very (add more ‘very’ here) short list of books with “Stata” in the title (the list excludes Reference Manuals). Here are my search results:

University of the Philippines Integrated Library System
Principles of biostatistics / Marcello Pagano
A handbook of statistical analyses using Stata / Sophia Rabe-Hesketh and Brian Everitt
Statistics with Stata : updated for version 9 / Lawrence  Hamilton
An introduction to modern econometrics using Stata / Christopher Baum
An Introduction to survival analysis using Stata / Mario Cleves, William Gould, and Roberto Gutierrez

Ateneo de Manila University Rizal Library
Microeconometrics using Stata / A. Colin Cameron and Pravin Trivedi

De La Salle University Library
Statistics with Stata : updated for version 7 / Lawrence Hamilton
Practical statistics : a quick and easy guide to IBM SPSS statistics, STATA, and other statistical software / David Kremelberg

University of Santo Tomas Miguel de Benavides Library
Practical statistics : a quick and easy guide to IBM SPSS statistics, STATA, and other statistical software / David Kremelberg

Why the dismal list? I have no answer.

New Year’s Resolution

Vacation is finally over. Besides HBO, Discovery, and Animal Planet, I have spent my break reading Scott Long’s The Workflow of Data Analysis Using Stata (Workflow). Except for the frequent “YOU’RE GUILTY” flags that flash before me in almost every page, I definitely enjoyed the Workflow. It got me to think of how I use to do things and, more important, the Workflow showed me how to improve them or how to do things right.

Since it is the time for New Year’s resolutions—the list of things you promise yourself and hope that you actually accomplish half of the list—I made a short list of my own:

1. Create a proper Research Log for every project. My work notes are everywhere. If I am asked what I did for a certain task, I consult my incomprehensible hand written notes in my physical notebook and my comments and do-files, data files, or other e-files in my computer. Most of the time, I could find what I am looking for, but only after wasting so much time.

The Workflow (p. 41) provides an example of a Research Log. One look at this snapshot of a research log will give so much information on what has been done and when, which files does which tasks, and more. I can only imagine how much time I should have saved if I had something similar to this.

2. Document now, not later! This is rephrasing Long’s law of documentation (p.34): “It is always faster to document it today than tomorrow.” Reading this part of the book reminds me of a recent (re)work that I and a colleague did before the Christmas break. We had to rerun all the do-files we wrote for a certain paper because we cannot replicate some of the tables. Two days of work gone because of poor documentation.

3. Follow the Workflow’s posting principle (p.125): “Once a file is posted, it should never be changed.” So G-U-I-L-T-Y!

4. Never name a file “final” (p.137). I actually have a file named final.dta and another final_new.dta and another final_new2.dta. What a mess!

5. Practice using Stata’s -datasignature- feature (p.139).

6. Backup and archive properly. The Workflow devotes a whole chapter (ch. 8 ) on protecting files. When some of my do-files were corrupted for reasons only my computer knows, I had to re-type them (my only back up were the ones I printed). Shame.

So help me God.

Happy New Year everyone! =)

Stata on YouTube

Stata is already on Facebook and Twitter and is also on “Blogosphere.” Looking at xkcd‘s Map of Online Communities (below), another place to be on is YouTube. Wondering whether Stata is on YouTube, I searched and found that there are actually lecture videos on Stata (not by StataCorp). Among the firsts that appear on the search is the series of lectures, which they called “Stata Video Project,” posted on the YouTube channel of the College of Liberal Arts, University of Minnesota (links below). The posts actually got good reviews and more requests.

xkcd: A webcomic of romance, sarcasm, math, and language.

Unlike geographical maps, whose changes are too slow to be noticed in a lifetime, the map of the online world will consistently change and in significant ways. Business models will never be the same.



Links to the 8-part Stata lecture series (College of Liberal Arts, University of Minnesota YouTube Channel):

STATA Video #1 Introductions

STATA Video #2 Introductions II

STATA Video #3 Introductions III (Part A)

STATA Video #3 Introductions III (Part B)

STATA Video #4 Linear Regression (Part A)

STATA Video #4 Linear Regression (Part B)

STATA Video #5 Logistic Regression (Part A)

STATA Video #5 Logistic Regression (Part B)

STATA Video #6 Poisson and NB Regression

STATA Video #7 Quantile Regression

STATA Video #8 Fixed and Random Effect Models

Where can you buy Stata Press books in the Philippines?

Nowhere. Not even on-line. But you can contact Columbia CP, Stata’s distributor, and they can order the books for you from Hong Kong. They will, however, charge additional fees for freight and bank processing. In addition, Customs will hold your books hostage until you pay import duties and taxes (why books are taxed is another sad story). With all these extras, the two books I ordered from Amazon would have cost more than twice!

You can also order books via Amazon and ship them directly to your Philippine address, but  you will be charged a not-so-cheap shipping cost and (again) Customs will hold your books hostage until you pay import duties and taxes. If you choose express shipping (e.g. FedEx), Amazon will charge the estimated custom’s duties so you will not deal with Customs yourself.

But if you have friends or family coming home from the US, order from Amazon and ship the books to them. This is easier and cheaper! Can’t wait for Ma’am O* to come home this December, she has my copy of Christopher Baum’s An Introduction to Stata Programming and J. Scott Long’s The Workflow of Data Analysis Using Stata.


*Our highshcool chemistry teacher and math coach who is now teaching in California (another sad story: best teachers are gone to teach in the US) kindly offered to bring home the books for me when she saw my Facebook post ranting about book taxes. Thanks, Ma’am O (her first name is truly just “O”).

Reading IMEUS

I am currently reviewing econometrics by reading Christopher Baum’s An Introduction to Modern Econometrics Using Stata.* Although linear regression is not discussed until chapter 4, chapters 1 to 3 (particularly chapter 3) are equally important (I finished chapter 3 last week…long way to go given my current rate of <1 chapter a week). Afterall, before anyone complicates his life with all those regressions, one needs to be sure that the data is “clean” and structured in such a way that it is fit for the analyis required. In fact, I think that the time spent on data management is so much more than the time spent on the actual data analysis.

Here are some of the things I remember about the first three chapters of the book. The discussion of Stata’s features in chapter 1 made me appreciate Stata even more. Chapter 2 outlines the basic tools one needs to learn to efficiently work with Stata. This chapter provided me very helpful tips on how to handle missing data and dates. And in chapter 3, I especially liked the section on data validation, which introduced me to the command -assert-. If only I knew -assert- when I was “cleaning” the QIDS dataset (7 years ago), it would have been easier to do all those consistency checks. Instead of running each line one by one, using -assert- would have allowed me to run the whole do-file but will stop and let me know whenever conditions are not met. So much for regret…

On to the next chapter…

*Thanks to Ellen and Jo Cain for leaving me this book before they left for the US :)