In my previous post I cautioned against looping across observations, then showed how to do it anyway, using the example of reshaping a list from long to wide. A reader suggested, not unreasonably, that one might want to use reshape for that. He then proceeded with a code example, under the reservation that he did [...]
Archives for the Month of November, 2008
Looping across observations
Wednesday, 26 November 2008
People who stress that you very seldom have to do this in Stata are right. That's why I always forget how it's done. So here, for my reference and yours: Today I looked at a table in .rtf format. It had test scores for a bunch of students in Poli Sci at the University of [...]
Arguments
Wednesday, 26 November 2008
In an older post I wrote about the program capability in Stata. One thing I didn't say and I find increasingly useful these days is that you can pass arguments to programs. Packaging a set of commands inside a program, to be read once and then invoked as many times as they are needed, is [...]
Data from MS Access to Stata
Friday, 21 November 2008
In my oldest post about the odbc load command I mentioned that you can pretty easily read data from MS Access into Stata, and even execute SQL commands from within Stata, but I dismissed the whole thing a bit too lightly. A recent look on Google Analytics showed that some people came here looking for [...]
Looking at your data: table vs. tabulate
Wednesday, 19 November 2008
Last night I got an e-mail from a reader, asking how to keep Stata from clipping long string values in two-way tables. This is his code: clear set obs 10 gen a = "" replace a = "a123456789b123456789c123456789" if _n<5 replace a = "987654321x987654321y987654321z" if _n>=5 gen b = "value " + string(int(_n/4)) tab a [...]
Data from Excel to Stata, take two
Wednesday, 12 November 2008
I don't like spreadsheets. I like data sets and matrices. But I get data in Excel workbooks all the time, and it's a pain in the neck. This will never go away altogether, but if my Stata-using colleagues could be persuaded to quit sending me spreadsheets, that would at least cut down on the volume. [...]
Leading zeroes
Tuesday, 11 November 2008
I am working on a project where occasionally I need to keep time using dates in the format YYYYMMDD. I sometimes also need to move back and forth between these dates and numeric year, month, day, which requires things like turning the numeric month 1 into the string "01". The general syntax for turning numbers [...]
Old-school summary statistics
Monday, 10 November 2008
If you do this sysuse auto sum price, detail return list you will see that Stata saves summary statistics in a few scalars with some rather apt names, like r(N) for count, r(mean) for mean, or r(p99) for the 99th percentile. Those names used to be far less descriptive until a few years back. If [...]