Announcement

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

  • SVMAT produces confusing message

    Dear All, consider the following code:

    Code:
       clear all
       matrix A=1,2,3\4,5,6
       set obs 2
       svmat A
    When run in Stata 16.0 for Windows it results in the following messages:
    Code:
    .    clear all
    
    .    
    .    matrix A=1,2,3\4,5,6
    
    .    set obs 2
    number of observations (_N) was 0, now 2
    
    .    
    .    svmat A
    number of observations will be reset to 2
    Press any key to continue, or Break to abort
    number of observations (_N) was 0, now 2

    This is confusing, since the number of observations before -svmat- is run is already 2, not 0 as stated in the message. In fact the message appears always, regardless what is the number of observations, whether zero, smaller than roswof(A), or equal, or bigger.

    This is preventable if other variables exist in the dataset when -svmat- is called, but not for a completely empty dataset.

    If this is a known issue or already fixed, please disregard. Otherwise, I believe there should be no change to the _N observations set by the user before svmat is called even if it is excessive. Correspondingly, if the message is issued, it should refer to the correct _N (set by the user), not zero.

    Thank you, Sergiy Radyakin

  • #2
    I get the same message text as you using version 16.1 (and versions right back to 12.1 -- not shown). On the upside, there is not an error message halting execution. On the downside, there is the issue you refer to.

    Code:
    
    . clear all
    
    .    matrix A=1,2,3\4,5,6
    
    .    set obs 2
    number of observations (_N) was 0, now 2
    
    .    svmat A
    number of observations will be reset to 2
    Press any key to continue, or Break to abort
    number of observations (_N) was 0, now 2
    
    . de  
    
    Contains data
      obs:             2                          
     vars:             3                          
     size:            24                          
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                  storage   display    value
    variable name   type    format     label      variable label
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    A1              float   %9.0g                 
    A2              float   %9.0g                 
    A3              float   %9.0g                 
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Sorted by: 
         Note: Dataset has changed since last saved.
    
    . list
    
         +--------------+
         | A1   A2   A3 |
         |--------------|
      1. |  1    2    3 |
      2. |  4    5    6 |
         +--------------+

    Comment


    • #3
      Dear Stephen,

      thank you very much for confirming with other Stata versions. The -svmat- code still runs under version 4.0 compatibility
      You are correct, this is not an error preventing execution (the red color was used by me to highlight which message I found confusing).

      Another strange behavior I've noticed is that the message to "press any key to continue, or Break to abort" appears also in the situation where -more- is off (which is at least my default). So it is useless and Stata doesn't wait for you to read the message and make a decision.

      One could do:
      Code:
      if "`c(more)'"=="on" display "Press any key..."
      otherwise just skip it to avoid a message alltogether.

      Stay safe!

      Regards, Sergiy

      Comment


      • #4
        Oh, boy, am messing around with svmat and matnames and, frankly, it's a mess. Seems like a very neglected area of Stata that no one wants to fix... I just wanted to output a matrix as a dataset and an hour later I have not accomplished much.

        I am assuming there is a better way, but haven't figured it out yet. I see there is a user-written program at SSC called "xsvmat" and am about to give that a try.

        Comment


        • #5
          1) I don't know what is going on, but it seems like the -clear- is what triggers this problem. If I do clear, clear all, or drop *, then I get the message but not if I start with a regular data set. Unfortunately, I don't want to overlay a matrix on top of an existing dataset (obviously), but that seems to be the trigger FWIW.

          2) I ended up prefixing my svmat with capture, which is not ideal, but was the least bad thing I could come up with fairly quickly.
          Last edited by John Eiler; 07 May 2020, 15:36.

          Comment


          • #6
            It only makes sense when -more- is on, which gives you the option to break out. Anyway, I will look into fixing it in a future update.
            Last edited by Hua Peng (StataCorp); 07 May 2020, 15:54.

            Comment


            • #7
              Thank you very much for looking into the outlined issues with svmat.

              Comment


              • #8
                Kind of silly but another workaround is to create a dummy column and then drop it, e.g.

                Code:
                clear all
                matrix A=1,2,3\4,5,6
                set obs 2
                gen x = .
                svmat A
                drop x

                Comment


                • #9
                  Yes, as I wrote in #1:
                  This is preventable if other variables exist in the dataset when -svmat- is called, but not for a completely empty dataset.
                  It is also possible to completely rewrite svmat to avoid the problem all together. But best is probably just to fix it at the source, and since it is a Stata's base command, counting on Mr. Hua Peng now.

                  Comment


                  • #10
                    Originally posted by Sergiy Radyakin View Post
                    Yes, as I wrote "This is preventable if other variables exist in the dataset when -svmat- is called, but not for a completely empty dataset."
                    Oh, thanks, I did not notice that the first time. In any event, hopefully what I wrote is a nice code example of the simplest way to do that (as keeping an entire existing dataset there is much harder to get rid of than typing "drop x" as in my example). At this point I'm much more interested in short term fixes and would be grateful if other people have better workarounds, since a fix from Stata is probably months away and even then only helps if you have version 16.

                    I agree, of course, that if Hua Peng can re-write -svmat- then that is a much better fix, and I hope that happens.

                    Bigger picture question here for me, at risk of going off on a tangent here, is just trying to export a matrix (some post-estimation parameters) as a CSV, and this took me a lot longer than expected as any method I could come up with takes several lines and the svmat/matname part of it was a bit trickier than I think it needed to be (exporting a dataset as a CSV is of course very easy and painless).
                    Last edited by John Eiler; 08 May 2020, 07:05.

                    Comment


                    • #11
                      Bigger picture question here for me, at risk of going off on a tangent here, is just trying to export a matrix (some post-estimation parameters) as a CSV, and this took me a lot longer than expected as any method I could come up with takes several lines and the svmat/matname part of it was a bit trickier than I think it needed to be (exporting a dataset as a CSV is of course very easy and painless).
                      Ben Jann's command estout/ esttab from SSC provides a one-line solution to this problem.

                      Code:
                      sysuse auto, clear
                      regress mpg weight disp gear
                      mat b= e(b)
                      *ssc install esttab
                      esttab mat(b) using myfile.csv, nomtitles 

                      Comment


                      • #12
                        Thanks, Andrew! That's what I needed (or at least very close).

                        Comment

                        Working...
                        X