-destring- uncomplicated


In a comment to the previous post destring complication: negative numbers, Nick Cox pointed out “the most important advise” in using destring: “never destring, replace unless you are absolutely sure that you are right or are willing to do things again if you made the wrong decision. The generate() option is there for a purpose.”

In addition, his comment point to simpler solution than using regular expressions.

Continue reading

-destring- complication: negative numbers


Less than 2 hours flight…

In a Stata training, one of the students wondered why after importing an Excel file of financial indicators into Stata some were read as strings. A quick browse at the data indicates the presence of hyphens (“-“) and that these were used in different ways: one to indicate a negative number and another to indicate a missing observation.

hyphen

How do we convert these variables to numeric as destring returns an error?

Continue reading

Import data from Excel sheets


How do we import data from all sheets in a number of Excel files? Each Excel file has a different number of sheets with names of no discernible pattern, but (thankfully) each sheet has the same structure: the first observation is in the same row and the columns correspond to each other. An example is the set of 17 Excel files of census data of barangays (villages) that was provided to me. Each Excel file corresponds to one region and within each file are sheets corresponding to the province in the region.  How do we consolidate all sheets in all files into one data file?

Continue reading

Haiku: cls


clean results window
in Stata thirteen, typing
cls clears screen

 

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

break me


Sometimes we want to break a continuous variable into a smaller set of categories—into evenly spaced or equally sized groups, or groups based on limits we specify, or groups based on another variable or a set of variables.

Let us take for example the variable price of cars in auto.dta.
sysuse auto.dta, clear    // open a Stata built-in data
summ price

Continue reading

Put anything anywhere in Excel without sweat


putexcel has recently become a very good friend. For those who (or working with people who) find comfort in working with tables in Excel after data processing or estimation in Stata (yes, there are others who don’t find comfort in this.) and already into Stata 13, learning putexcel could be very helpful (put an end to copy-pasting!). A number of user-written commands, such as outreg [1], outreg2, tabout, are also already available for similar purposes. What puts putexcel apart is its ‘user-friendliness’ and flexibility. You can put anything anywhere in Excel without sweat.

Continue reading

No -usespss- for Mac


In Reading SPSS data file into Stata, I describe Sergiy Radyakin’s -usespss- that loads SPSS data (.sav) into Stata. I was on Windows then. -usespss- is unfortunately not available for Mac OS. StatTransfer could easily do this if you have the software. Another option is to use R.

A quick Google search led me to a simple R routine that does exactly this. Following the steps outlined in Daniel Marcelino’s Loading SPSS (.sav) into Stata, I managed to covert an SPSS data set I downloaded from IDRA UCLA website into a Stata .dta file.

Try it out! It is easy to follow.

An interesting extension is Gabriel Rossman’s importspss.ado (requires R). It implements the R routine as an ado-file.

Tell me, where did I go wrong


If you are Filipino, you are most likely singing the title by now :)

Looking for a missing bracket, a misplaced comma, or a space that shouldn’t be there—or debugging in general—can be a pain sometimes. When the usual error message fails to point out where you messed up, try turning trace on to track down the error. trace literally traces the execution of programs. It echoes the lines that Stata executes internally. Reading through the whole thing on your results window can be daunting but you don’t really have to go through those. You just need to know which line it stops executing and see why it stopped there. To turn on trace, type:

set trace on
And.. don’t forget to turn it off when you don’t need it. They can be really very long.

set trace off
Next time you wonder where you went wrong, use trace before you lose your mind. For more options, see help set trace.

Now, continue with the singing.. “what did I do to make you change your mind completely..”

 

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 ;)