Hi,

I am working with the userwritten command -esttab-, and have been referring to the following examples:

http://repec.org/bocode/e/estout/adv...ml#advanced907

I am trying to flip some models so I am using the Approach 2 under the heading: "Flip models and coefficients (place models in rows instead of in columns)".

As I am going to use the subroutine frequently I have tried to convert the subroutine into an ado file as follows:
Code:
capt prog drop flipmodel

*! version 1.0.0  Ben Jann
program flipmodel, eclass
     // using active equation of model
     args est
     version 14.1
     tempname b se C tmp
     esttab `est', se nostar
     mat list r(coefs)
     matrix `C' = r(coefs)
     local rnames : rownames `C'
     local models : coleq `C'
     local models : list uniq models
     local i 0
     foreach name of local rnames {
     local ++i
     local j 0
     capture matrix drop b
     capture matrix drop se
     foreach model of local models {
         local ++j
         matrix `tmp' = `C'[`i', 2*`j'-1]
         if `tmp'[1,1]<. {
             matrix colnames `tmp' = `model'
             matrix `b' = nullmat(`b'), `tmp'
             matrix `tmp'[1,1] = `C'[`i', 2*`j']
             matrix `se' = nullmat(`se'), `tmp'
         }
     }
     ereturn post `b'
     quietly estadd matrix `se'
     eststo `name'
}
end
Next, as an example to demonstrate the problem I am facing, I try out the subroutine from above:
Code:
sysuse auto
eststo model1: quietly reg price weight
eststo model2: quietly reg price weight mpg
flipmodel model*
esttab weight mpg _cons, se mtitle noobs
As you can see if you compare with the example in the link, I am neither getting the stars nor the SEs. Can someone please tell me if the ado file has some mistakes? Thank you in advance!