Announcement

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

  • Table command will not change counts after adding frequency weights

    Hello Statalist,

    My question probably has a very simple answer, but I am stumped nonetheless. I am using the following data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int year byte prov int fweight
    2017 12 134
    2017 12 106
    2017 10 179
    2017 10  73
    2017 13  91
    2017 13  76
    2017 12 113
    2017 12 221
    2017 13 172
    2017 13 170
    end
    label values prov PROV
    label def PROV 10 "Newfoundland and Labrador", modify
    label def PROV 12 "Nova Scotia", modify
    label def PROV 13 "New Brunswick", modify
    I create the following table:

    Code:
    table (year) (prov) (), statistic(freq)
    
    -------------------------------------------------------------------------------------------------------
                |                                          Province                                        
                |  Newfoundland and Labrador   Prince Edward Island   Nova Scotia   New Brunswick     Total
    ------------+------------------------------------------------------------------------------------------
    Survey year |                                                                                          
      2017      |                     45,234                 32,334        64,728          62,456   204,752
      2018      |                     44,905                 33,317        64,792          62,108   205,122
      2019      |                     45,030                 32,403        62,224          61,301   200,958
      Total     |                    135,169                 98,054       191,744         185,865   610,832
    -------------------------------------------------------------------------------------------------------
    I need the table to be weighted, so I follow the code presented in the Table COmmand documentation:

    Code:
    table (year) (prov) () [fweight=fweight], statistic(freq)
    
    -------------------------------------------------------------------------------------------------------
                |                                          Province                                        
                |  Newfoundland and Labrador   Prince Edward Island   Nova Scotia   New Brunswick     Total
    ------------+------------------------------------------------------------------------------------------
    Survey year |                                                                                          
      2017      |                     45,234                 32,334        64,728          62,456   204,752
      2018      |                     44,905                 33,317        64,792          62,108   205,122
      2019      |                     45,030                 32,403        62,224          61,301   200,958
      Total     |                    135,169                 98,054       191,744         185,865   610,832
    -------------------------------------------------------------------------------------------------------
    Why are my weighted frequencies the exact same as my unweighted ones? I cannot seem to understand what I am doing wrong. The weight variable is an integer, all variables are numeric, and when I use the tab command the weight gets applied:

    Code:
     tab year
    
    Survey year |      Freq.     Percent        Cum.
    ------------+-----------------------------------
           2017 |    204,752       33.52       33.52
           2018 |    205,122       33.58       67.10
           2019 |    200,958       32.90      100.00
    ------------+-----------------------------------
          Total |    610,832      100.00
    
    . tab year [fweight=fweight]
    
    Survey year |      Freq.     Percent        Cum.
    ------------+-----------------------------------
           2017 | 23,837,742       33.16       33.16
           2018 | 23,944,158       33.31       66.48
           2019 | 24,094,694       33.52      100.00
    ------------+-----------------------------------
          Total | 71,876,594      100.00
    I appreciate any insights into this! Thank you in advance.

  • #2
    I have since found the answer: use
    Code:
     
     table (year) (prov) () [fweight=fweight], statistic(sumw)

    Comment


    • #3
      Hello, a related to question to this, if i want a table like the above table to be exported as latex table then what do i need to do?

      Comment


      • #4
        Please see the FAQ extras, namely
        1.5 Starting a new thread

        If you have what is essentially a new and different question, it is generally best to start a new thread. A cross-reference to the previous thread is helpful if there is a relation.
        David Radwin
        Senior Researcher, California Competes
        californiacompetes.org
        Pronouns: He/Him

        Comment

        Working...
        X