Tuesday, 16 March 2010
With one variable, that's easy enough: count if missing(variable-name). If you have several variables, you can put them in a foreach loop. But if you have to do this for arbitrary lists of variables in several files, it may be interesting to package that foreach loop inside a quick command that might handle special display instructions as well.
Here is one suggestion:
// countIfMissing: display the total count of observations, then
// any counts of missing observations for each variable in a list.
capture prog drop countIfMissing
program countIfMissing
version 11
syntax varlist
quietly count
local count=r(N)
// now make things align nicely
local sum=`count'
local tens=1
while `sum'/10>1 {
local sum=`sum'/10
local tens=`tens'+1
}
local width=`tens'+int(`tens'/3)
local varct: list sizeof varlist
di ""
di "Observations:"
di %`width'.0fc `count'
di ""
di "Missing:"
foreach varble in `varlist' {
qui count if missing(`varble')
local ct=r(N)
local pct: di %4.2fc 100*`ct'/`count'
if `pct'>0 {
di %`width'.0fc `ct' " `varble' (`pct'%)"
}
else {
local varct=`varct'-1
}
}
if `varct'==0 {
local offset=`width'+2
di _column(`offset') "none of `varlist'"
}
di ""
end
For an example of usage, you can try this:
sysuse auto
local myvars "make price foreign"
countIfMissing `myvars'
countIfMissing m* // (1)
countIfMissing _all // (2)
As you can see in (1) and (2), the usual varlist conveniences apply here.
Tags: missing(), syntax
Posted in Stata | No Comments »
Tuesday, 2 March 2010
Last week I mentioned that in the course of switching from Notepad++ to Vim I lost the ability to run Stata do-files or selected lines from within the text editor, and I asked my readers for help if they had a solution. What do you know, one of them did, and wrote to me all [...]
Tags: text editors, Vim
Posted in Stata | No Comments »
Sunday, 28 February 2010
When it comes to defining local macros in a different place from where you use them, you have two options: a do-file you include as needed or an r-class program that you call as needed. I talked about it here and said that a program is a better choice, without any evidence to back up [...]
Posted in Stata | 2 Comments »
Friday, 26 February 2010
I was looking for an excuse to try something new and I decided to pick on one Notepad++ shortcoming that was handy: the Stata syntax highlighting gets utterly mangled after compound quotes -- `"`like so'"' -- which do sometimes arise, usually in the process of file open/file write.
Vim does not get confused by compound quotes and [...]
Tags: syntax, text editors, Vim
Posted in Stata | No Comments »
Tuesday, 23 February 2010
The other day I wrote a program that needed to call a file as an argument -- with the full file path. My first pass at it was to capture the argument as usual, with say args input_file. But that would not have worked with file paths that have spaces in them. What might have [...]
Tags: syntax
Posted in Stata | 1 Comment »
Thursday, 18 February 2010
In The Stata Journal Vol. 9, No. 3, 2009 there's a Stata tip (# 77) on re-using macros in multiple do-files, by Jeph Herrin. His solution is to define any local macros in a separate do-file, say locals.do. You can call that do-file with the include command at the top of any do-file that might [...]
Tags: include, local macros, program
Posted in Stata | 3 Comments »
Friday, 15 January 2010
This is a revision of my earlier assessment that tsclient is so slow it's useless. The thing came back to life somehow and it looks like it's thanks to either Dell or Microsoft. I upgraded to Karmic over Christmas with some hope that it might fix tsclient, but nothing changed. Then the server in Atlanta [...]
Posted in Ubuntu | No Comments »
Thursday, 7 January 2010
On December 11, 2009 portaudit turned up a problem in a package called libtool-2.2.6a_1. So, as usual, I figured I'd go to whatever port that is, and do a portupgrade. Unfortunately, whereis libtool turned up no such port. What's the rookie accidental admin to do?
Take good notes, for one. While dabbling in an unrelated topic -- [...]
Posted in FreeBSD | No Comments »
Wednesday, 2 December 2009
My migration to Ubuntu has just hit a major snag.
I spend most of my work day connected to a Windows Server 2003 machine sitting in a colocation facility in Atlanta. I write and run Stata code on it, use the MS Office products, a bit of Gmail -- the usual stuff. As it turns out, [...]
Posted in Ubuntu | No Comments »
Thursday, 12 November 2009
One drawback of a system that's giving you very little trouble is that between bouts of fixing whatever does occasionally go wrong you forget what you're supposed to do. We should all be this lucky, but it's still an annoyance.
FreeBSD, for example, will sometimes turn up a damaged package or two in response to #portaudit. [...]
Tags: portaudit, portupgrade
Posted in FreeBSD | No Comments »