Stata programming question

Hi. I don’t know that this is the best place to ask, but I can’t think of where to go—it’s an extremely basic question.

I have pretty extensive experience with (ahem) normal programming languages, but Stata is giving me fits. I’m trying to figure out how to use ereturn to post estimation results, but I’m getting the most bizarre error. Parsimonious nonsense example:



program define silliness, eclass
   ereturn clear
   
   tempname b V
   matrix input b = (2, 2)
   matrix input V = (2, 3 \ 3, 2)
   
   // This works, making (2, 2) available in e(b):
   // ereturn post b

   // But this doesn't---it throws a "name conflict" error. WTF?!
   ereturn post b V
end


Changing the name of the variance matrix does nothing. I’ve played around with macro substitution a bit, trying to figure out the calling convention, but the best I could do is no error and an empty e(V). Argh, what am I doing wrong?

It’s been a while since I’ve used Stata, but did you try b' V’ instead?

Anyway, when I ran into problems I had pretty good luck with statalist: http://www.stata.com/statalist/

Figured it out! (For what it’s worth; I’m sure everybody was waiting with bated breath, clicking “reload” over and over again until I responded.)

I had made two errors. First: Stata seems to want the names of the columns in the coefficient matrix to match up with the names of the corresponding rows/columns in the variance matrix. Thus “name error”. I suppose this is reasonable, but it is not documented anywhere as far as I can tell. (All the examples in the user’s guide reuse previous ereturns, how helpful!)

Second: when I fixed the above, I received a “variance matrix is nonsymmetric or highly singular” warning. This is odd because my pulled-from-the-air matrix is neither asymmetric nor singular. Perhaps I’m dim somehow, but I don’t see why Stata saw it right to reject my matrix a priori and replace every entry with zeros. “You are lying to me, James,” Stata said, “So I shan’t play with you at all.”

Here’s a working example for posterity.



program define simple_ols, eclass
   tempname b V
   matrix input b = (1, 2)
   matrix input V = (4, 3 \ 3, 10)

   matname b a1 a2, columns(.) explicit
   matname V a1 a2, explicit

   ereturn post b V
end



I appreciate that! That is a good resource to have in my toolbox. It’s too bad that everyone around here uses SAS, they are naughty academic economists and a bad influence on me.

This is embarrassingly easy, but I’m very new at this.

I’m trying to download a data set off of IPUMS and I don’t know how to get the information or redirect it.

I’ve saved it in a folder as IPUMS and I decompressed it so it now reads usa_00001.dat but each time I type into Stata I say

cd
cd"C:\Documents and Settings\mlynch2\My Documents\IPUMS"
do usa_00001.do

it lists all the variables and then says usa_00001.dat not found and end of do-file.

Your original covariance matrix wasn’t positive definite, which is definitely a problem. I could see that causing an error message like this if they didn’t think about that case during the implementation.

Do you mean that it’s a dta file? Is that a typo? Or is it really a dat file?