Announcement

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

  • "frequency weights must be integers"

    I am trying to use frequency weights. My variable that I am trying to use as weights is integer values. I have tried to recast as byte and long. I have replaced all missing values with zero. It still gives an error message of "Frequency weights must be integers r(401)". Any ideas on how to fix this?

  • #2
    From what you say the real question is: who is wrong about the variable being integer, you or Stata?

    You can get an idea of non-integer values by e.g.

    Code:
     
    tab myvar if floor(myvar) != myvar

    Comment


    • #3
      It would help to see exactly what you typed (see the FAQ in this regard). I would guess (all I can do without seeing what you typed) that you have some other kind of syntax error.

      Regards, Mike

      Comment


      • #4
        @Nick I checked your command "tab N if floor(N) != N" and the result is "no observations"

        @Mike - this is the command I am trying to use "tabout temp using ${output}table_10.xls [fw=N], sum oneway append f(1p 1p 1p 1p 1p 1p 0c) ///
        c(p25 frac_2014_AdR mean frac_2014_AdR p75 frac_2014_AdR)"

        I have been able to construct a work-around by using the "expgen" command, so this resolves to get me the answer I need, but doesn't help me to understand why Stata (and I guess fweights) isn't recognizing my values as integers.

        Comment


        • #5
          Any zeros or negative values?

          Code:
           
          codebook N 
          su N, detail 
          tab N
          might help.

          Comment


          • #6
            No zeros or negative values. And it doesn't make sense that fweights isn't recognizing the values as integers because "expgen" did recognize the values as integers! Not sure what's going on here. Thanks for the help!

            Comment


            • #7
              Note that -tabout- is a user-written add-on (albeit an excellent one), as is -expgen-, which helps to know. I'd try -set trace on- and then run your -tabout- command and see if you could figure which of the many Stata commands called within -tabout- is occasioning the error message. This trace it likely to generate a lot of output, so I'd log the output in case it overflow your scrollback setting.

              Regards, Mike

              Comment


              • #8
                Lindsey- Were you able to resolve this problem? I'm getting the same error message: "Problem with frequency weights r(401)".

                Here is the code:

                input a b F
                0 0 186176
                0 1 8822
                1 0 56955
                1 1 3747
                end

                tab a b [fw=F], row exp chi2 cchi2
                tabout a b [fw=F] using secapp.txt, replace cell(freq row) f(0c 2p) layout(row) stats(cchi2)

                I have run the diagnostics suggested above and nothing suggests that Stata is not recognizing the variables as an integer.

                Code:
                 describe
                
                Contains data
                  obs:             4                          
                 vars:             3                          
                 size:            48                          
                ---------------------------------------------------------------------------------------------------------------------------------------
                              storage   display    value
                variable name   type    format     label      variable label
                ---------------------------------------------------------------------------------------------------------------------------------------
                a               float   %9.0g                 
                b               float   %9.0g                 
                F               float   %9.0g                 
                ---------------------------------------------------------------------------------------------------------------------------------------
                Sorted by:

                Code:
                . tab F if floor(F) != F
                no observations
                Here is the relevant portion of the trace results:

                Code:
                - capture file close `outfile'
                = capture file close __000001
                - }
                - local weightstr1 = cond("`weight'"~="","`weight'","none")
                = local weightstr1 = cond("fweight"~="","fweight","none")
                - local weightstr2 = cond("`weight'"~="",subinstr("`exp'"," ","",.),"none")
                = local weightstr2 = cond("fweight"~="",subinstr("= F"," ","",.),"none")
                - if ("`weightstr1'"~="none") {
                = if ("fweight"~="none") {
                - local wtvar = substr("`weightstr2'",2,.)
                = local wtvar = substr("=F",2,.)
                - local wttype : type `wtvar'
                = local wttype : type F
                - if ("`weightstr1'"=="fweight" & "`wttype'" ~= "byte" & "`wttype'" ~= "int" & "`wttype'" ~= "long" & "`chkwtnone'"=="") {
                = if ("fweight"=="fweight" & "float" ~= "byte" & "float" ~= "int" & "float" ~= "long" & ""=="") {
                - di
                
                - di as err "Problem with frequency weights {search r(401)}"
                Problem with frequency weights r(401)
                - di




                What gives? I know that "tabout" is not officially a part of Stata, but I know that there are a lot of folks on here who know about the user-contributed routines (and I believe the author may be on the list). In short, I would be very grateful for any help.



                Web site:
                ​http://investigadores.cide.edu/crow/


                Las Américas y el Mundo:
                http://lasamericasyelmundo.cide.edu/

                ==========================================
                David Crow
                Associate Professor, División de Estudios Internacionales
                Centro de Investigación y Docencia Económicas (CIDE)
                ==========================================

                Comment


                • #9
                  tabout (SSC) evidently is surprised to find you storing weights in a float. Why I don't know. Try recasting it to a long.

                  Comment


                  • #10
                    Not sure if, "Why I don't know" means that you're not sure why tabout is surprised to find I'm storing weights as a float variable or why I'm storing them as float in the first place. If the latter, the answer is simple: that's the default storage type and I didn't know any better. That's why I'm grateful for this forum and for your patient response.

                    At all events, changing the storage type to long did the trick. Many thanks.
                    Web site:
                    ​http://investigadores.cide.edu/crow/


                    Las Américas y el Mundo:
                    http://lasamericasyelmundo.cide.edu/

                    ==========================================
                    David Crow
                    Associate Professor, División de Estudios Internacionales
                    Centro de Investigación y Docencia Económicas (CIDE)
                    ==========================================

                    Comment


                    • #11
                      I was surprised at tabout, not you. Sorry for the ambiguity.

                      Comment


                      • #12
                        No need to apologize. On the contrary, thanks for the help!
                        Web site:
                        ​http://investigadores.cide.edu/crow/


                        Las Américas y el Mundo:
                        http://lasamericasyelmundo.cide.edu/

                        ==========================================
                        David Crow
                        Associate Professor, División de Estudios Internacionales
                        Centro de Investigación y Docencia Económicas (CIDE)
                        ==========================================

                        Comment

                        Working...
                        X