Announcement

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

  • tab, no freq

    Hi!

    I have a do-file that was working perfectly, but now I'm running it again with an updated database, and when I get to the line where I run "tab varname, no freq" it appears to run but Stata doesn't show any results nor any error, like if I was doing a quietly tab.

    Thanks in advance for your help


  • #2
    Well, I think you need to show us exactly what command you gave and exactly what Stata did in response. When I run the command you show in your post, I definitely get an error messsage:

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . tab foreign, no freq
    option no not allowed
    r(198);
    That's because the space between no and freq is a syntax error. As for why you get nothing at all, it's hard to say. One possibility is that this is running inside a -capture- block.

    Anyway, show us what actually happened by copying from the Results window or your output log to your computer's clipboard and pasting into a code block. (See 7th paragraph of FAQ #12 for how to set up a code block if you don't already know). Don't edit that in any way. The details are often crucial to troubleshooting. Given what I said about the possibility of a -capture- block, you should show us not just this command and the output but the entirety of any block(s) of code (commands enclosed between { and }) that this problematic command is embedded in.

    Comment


    • #3
      Hello Clyde, thanks for your answer

      Here's the code:

      tab hhid, nofreq
      scalar hhid_unique=r(r)
      tab SbjNum, nofreq
      scalar SbjNum_unique=r(r)

      if hhid_unique!=SbjNum_unique {
      di "repeatead HHs"
      }

      I can't see the actual tab results, but I don't get an error, even if I run it separately

      Comment


      • #4
        I fail to understand. The nofreq option instructs the tab command to not display frequencies. Were you using the nofreq option prior to updating the database, and if so, what was tab showing you? Building on Clyde's example, her are the results of running tab before and after adding the nofreq option:
        Code:
        . sysuse auto, clear
        (1978 Automobile Data)
        
        . tab foreign
        
           Car type |      Freq.     Percent        Cum.
        ------------+-----------------------------------
           Domestic |         52       70.27       70.27
            Foreign |         22       29.73      100.00
        ------------+-----------------------------------
              Total |         74      100.00
        
        . tab foreign, nofreq
        
        .

        Comment


        • #5
          OK. This is the normal behavior of -tab, nofreq-. The default behavior of oneway -tab- is to display a table with the distinct values of, say hhid, along with the frequencies (counts) of each value, and their percentages and cumulative percentages. When you specify the -nofreq- option, you are telling Stata not to bother outputitng all of that. So Stata has done what you asked it to: it ran the tabulation internally and kept quiet about it. You can assure yourself, however, that the tabulations actually ran if you now do this:

          Code:
          scalar list hhid_unique
          scalar list SbjNum_unique
          and you will find the appropriate numbers.

          Normally, if you want to run a command and suppress its output (with the intent of accessing results in r()), you use the -quietly- prefix. But, for this particular command, -nofreq- accomplishes the same thing.

          The other, probably more common, use of the -nofreq- option is with twoway -tab-. There, in combination with the -row- or -column- option, you get a table showing the row or column frequencies but no counts--which is sometimes what you want.

          Comment


          • #6
            Thank you! I think I understand what happened, I forgot to type "di hhid_unique" so that I can see how many rows the command tab stored. There is actually no need to use ",nofreq" for what I needed.

            Thank you again!

            Comment

            Working...
            X