Announcement

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

  • SaveMat and SaveTable

    Good evening!

    I am editing some code from a previous analysis and came across the following code: preserve
    table vaccine vx_covcat [pweight=vx_wgt], replace
    SaveTable
    drop stat
    for X in var table0 table1 table2 table3 table10 table11 table12 \ Y in any "NoVax" "MotherReport" "Unknown" "NotYetDue" "EarlyTimely" "Late" "Indeterminable": ren X Y
    outsheet using Table1_VaxSummmary.out, replace
    restore

    When I run the code, the following error occurs: variable table* not found
    (error in option exclude())

    However, earlier in the do-file those code (SaveMat results Table1_Freqs) ran with no errors. I have never seen this code used before and couldn't find any literature on it so just wanted to ask if anyone else was familiar with it and would know what I could do to solve the error?

  • #2
    First, this is truly ancient code you are working with. That -for- construct, although it still can be used, was replaced by the various -foreach- commands in version 8, which was released in 2003.

    More important, there isn't enough information here to help you. You don't even say which command threw the error message. Whichever it was, apparently it was running at a time when your data in memory no longer contained any table* variables. Those are mentioned in the -for- command, but perhaps they were also needed for the SaveTable program, whatever that is. SaveTable is not an official Stata command, nor does it show up in a search of the usual places Stata's user-written programs are found. It may be the command that threw the error, or perhaps it destroyed table* variables that previously existed, thereby setting up the -for- command for failure.

    I strongly doubt anybody can help you unless you post back showing the code for the SaveTable command (or a link to where it can be found), and also some example data that you believe all of the code you showed should run with. When showing example data, please be sure to use the -dataex- command. If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      Thanks so much for the reply! I am sorry for not providing more information, I think some of it is that I am barely getting to grips with this code that is unfamiliar to me. As you mentioned, I am much more used to the updated code.

      As far as I can tell, the error is coming from the SaveTable line of code, as I am able to produce a table, as shown below after which the error message is shown. Unfortunately, I have no data that all the code should run with as I did not write or run the original code but was just asked to adapt it for a different dataset:

      table vaccine vx_covcat [pweight=vx_wgt], replace

      ------------------------------------------------------------------------------------------------------------------------------------------------
      | vx_covcat
      | No vaccination Mother report Vax status unknown Not yet due Early or timely, <=28d Late, >28d Indeterminable Total
      ----------+-------------------------------------------------------------------------------------------------------------------------------------
      vaccine |
      p0 | 2,589.11 766.403 2.88973 2,628.72 298.404 91.7518 6,377.28
      p1 | 713.916 1,021.8 2.02737 276.296 3,317.32 680.134 370.169 6,381.66
      p2 | 1,373.58 887.42 2.02737 439.881 2,551.46 878.745 255.94 6,389.05
      p3 | 2,061.78 490.726 2.02737 621.54 1,990.93 920.276 307.212 6,394.5
      penta1 | 347.976 930.558 24.8163 276.296 4,114.46 588.389 99.1742 6,381.66
      penta2 | 483.667 882.253 24.8163 439.881 3,436.62 956.657 165.158 6,389.05
      penta3 | 708.325 786.169 24.8163 621.54 2,829.92 1,242.36 181.365 6,394.5
      pneumo1 | 399.233 928.585 32.3184 276.296 4,030.13 597.881 117.222 6,381.66
      pneumo2 | 535.171 892.257 32.3184 439.881 3,361.66 952.12 175.645 6,389.05
      pneumo3 | 793.266 788.392 32.3184 621.54 2,738.39 1,236.28 184.305 6,394.5
      rota1 | 510.169 923.795 31.0897 276.296 3,905.15 606.666 128.503 6,381.66
      rota2 | 765.437 868.694 31.0897 439.881 3,148.91 976.47 158.566 6,389.05
      tb | 835.181 1,041.2 3,040.19 1,369.42 87.7618 6,373.76
      m1 | 706.821 770.387 15.6464 1,693.99 2,079.48 1,110.66 48.2949 6,425.28
      Total | 12,823.6 11,978.6 258.202 6,423.32 43,173.3 12,414.5 2,371.07 89,442.7
      ------------------------------------------------------------------------------------------------------------------------------------------------

      Comment


      • #4
        So, it seems that whatever this SaveTable program is and does, it expects to have variables named table*. Looking at the output of your own -table- command that reproduces the error, it is clear that it contains no variables with a name like that. So it boils down to three possibilities:
        1. The table that you are creating is the wrong table and you need to revise that command to create the appropriate table for SaveTable.
        2. There is a bug in SaveTable that causes it to look for variables named table* even though there is no reason it should expect them to exist at that point. Perhaps it is supposed to create those from the variables that are actually there but fails to do so for some reason.
        3. The SaveTable command is correct for what it is supposed to do, but it is not suitable for use with the data you are feeding it. Some command other than SaveTable needs to be applied.
        Without the code for SaveTable, there really isn't anything more I can say.

        Comment


        • #5
          Thanks so much, I appreciate all of your help so much! I was able to move forward through the code by running stata 15. I now cannot pull up help files for the appropriate version of stata and the table command has changed, would you know how to add frequencies/counts to this table? Currently the command is only displaying the mean.

          table vaccine vx_residence [pweight=vx_wgt], c(m vx__agetimely_cont) format(%9.1f) col

          Comment


          • #6
            I no longer have version 15, and my memory of the syntax that -table- had back then is fading. But I think this will do it:

            Code:
            table vaccine vx_residence [pweight=vx_wgt], c(freq m vx__agetimely_cont) format(%9.1f) col

            Comment


            • #7
              Clyde remembers correctly.

              If you have Stata 17 or newer, the help file for the old (version controlled) table command is available with help table_16.

              Comment

              Working...
              X