Archives for the Month of April, 2009

Dynamic arithmetic expressions

A couple of days ago I showed how you can use logical operators inside arithmetic expressions. The point of that post was that if you had three variables, called say _var1, _var2 and _var3, then you could build another variable, call it _var4, that counted row-wise their non-zero instances, like so:

gen _var4=(_var1!=0)+(_var2!=0)+(_var3!=0)

This was actually spun [...]

Join the Statalist

If you were looking up something Stata-related and Google sent you here, you may or may not be in the right place. What I know for sure is that you should definitely join the Statalist. I've benefited lots over the years from lurking there. Here's the latest example: somebody asked yesterday about an easy way to [...]

Doesn’t look like a number, but it is

I came across a data set with some variables in it that recorded actual measurements, so their values could be zero or higher. Then a need arose to quickly look up how many of these variables would have recorded anything -- in effect, separating the yes/no part from the how much -- and adding the [...]

Stata and Samba, BFF

What can a Stata user do with a Samba server? Pretty much the same thing you would do with any computer. My Stata is installed on my Windows PC. Now Samba allows me to store either do-files or data on the remote FreeBSD server and access them easily.
Suppose that the remote box were called myUnix. [...]

Another use for local macros: Stata graphs

Graphs are tricky beasts in every programming environment. There are so many ways in which you might want them that any command for drawing them will have to be laden with options and it will probably run over numerous lines.
Stata, from version 8 onward, has done a wonderful job of taking the pain out of [...]

Logical operators

This really should go under "more gems from the User's Guide". If you come to Stata like I did, with minimal previous experience with any kind of computer programming, you might not know this:
When you combine !, & and | (the logical operators NOT, AND and OR) in an expression you will want to make [...]