Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating a matrix from returned macros and scalars

    Hi,

    The aim is to create a matrix which can be exported to excel using -putexcel-.

    Code:
    sysuse auto
    local var mpg rep78 price
    tabstat `var', by(foreign) s(median mean) save
    return list
    -tabstat, save- results in the creation of:

    macros:
    r(name2): "Foreign"
    r(name1): "Domestic"
    matrices
    r(Stat2): 2 x 3
    r(Stat1): 2 x 3
    r(StatTotal): 2 x 3
    It would be useful to create a matrix which was a 3 x 6 matrix which is comprised of macros and matrices (ie almost identical in layout to the tabstat display in Stata). This matrix could then be transferred into Excel using -putexcel- and there is the need to only reference one cell (e.g. B3). Otherwise, there would be five elements to take across using -putexcel-.

    With this as background:
    1. Is it possible to create a matrix using these components? If so, which commands would I use?
    2. If the -tabstat, save- command returned only scalars [e.g. r(r1) r(r2) r(r3)], would it be possible to create a matrix with these? If so, is it the same command as for 1?
    Thanks,

  • #2
    Austin Nichols took over a helper program tabstatmat (SSC) written for the first part of your purpose. It predates putexcel as I recall.

    Comment


    • #3
      Code:
      matrix A = r(Stats1)\ r(Stats2)\ r(StatsTotal)
      Best
      Daniel

      Comment


      • #4
        Thanks Nick. Unless there was a user error when I saved it, it seems that the -tabstatmat- ado file is not seem compatible with stata 14. (Although, - help tabstatmat - functions!). The error message received when I use -tabstatmat- is "unexpected end of file" and r(612).

        Daniel, thanks for the code. When I try it with a 3x5 matrix stata issues a "conformability error" and r(503).
        Last edited by Dann Morgan; 12 Oct 2016, 14:40.

        Comment


        • #5
          I can't comment easily on your problem as you don't specify either the data you used or the code you tried. It's puzzling how many expect extra-sensory perception from people who answer questions!

          But I tried the example from the help in Stata 14 and it worked fine:

          Code:
          sysuse auto, clear
          tabstat mpg, by(rep78) s(n mean sd) save
          tabstatmat mpgstat
          tabstatmat mpgstat, nototal
          At a wild guess, you forgot the save option.

          Comment


          • #6
            Sorry Nick - I was just updating the post above with more detail. Nevertheless, I don't think the edit was sufficient.

            Unfortunately, I am unable to -ssc install tabstatmat- as the system times out. I have copied the text from https://ideas.repec.org/c/boc/bocode/s435001.html and saved it into ado file in C:\ado\plus. The sthlp file works fine.

            Comment


            • #7
              I'd check using

              Code:
              help netio
              that your Stata can talk properly to the internet. I have found

              Code:
              set httpproxy {on|off} [, init]
              set httpproxyhost ["]name["]
              set httpproxyport #
              to be crucial to my set-up. If relevant, then the way your browser is set up is a guide.

              Comment

              Working...
              X