Announcement

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

  • fweight ; weighting ; computing mean with weight

    Dear all,

    I would like to average some values inside a population of participants, my goal is that each value in the mean computation weight is the variable Freq . both the following syntax work but gives me the same values as the command without weight. Somebody could help me? Am I doing something wrong?
    NB: note that freq is a non-integer number

    Many thanks in advance for your time.

    Code:
        forval i = 1/24 {
        local varname Q1_`i'
        asdoc tabstat $kir if `varname' == 1 ,  weight(Freq) statistics(mean count) dec(2) save(TABLE3_NEW.rtf) append
    }
    
        forval i = 1/24 {
        local varname Q1_`i'
        asdoc tabstat $kir   if `varname' == 1 [fw=Freq], s(sum) dec(2) save(TABLE3_NEW.rtf) append
    }

  • #2
    If Freq contains non-integers then it is definitely not a frequency weight. If Freq contains non-integers in the subsample `varname' == 1, then your second command will definitely not work, i.e., result in error, because Stata does not allow non-integer frequency weights.

    It is hard to say much more. I suggest you drop the asdoc prefix and the locals and globals, and create a simple example, using dataex, with tabstat and three variables, that illustrates the problem.

    Comment


    • #3
      Like daniel klein I don't understand how non-integer weights would work here as frequency weights unless asdoc is doing something nonstandard.

      Please post an example that is reproducible. Is your problem with asdoc from SSC? tabstat (official command) doesn't support a weight() option so it seems that your problem is with asdoc and two ways of calling it.

      Hence asdoc should perhaps have been in the title and it's fair to ping its author Attaullah Shah
      Last edited by Nick Cox; 10 Oct 2023, 03:57.

      Comment


      • #4
        Yes, both of you are right: without asdoc doesn't work.
        To simplify things, could you guide me through a command that calculates the average while weighting by a non-integer number (in my case, "Freq" is the inverse of attendance at various events: 1/number of events attended)? My goal is to weigh more those who have only attended one event.

        Maybe i could reach the same goal with the following command and looking the mean ? Of course doesn't work because Freq is not integer number.

        Code:
        sum lev1 if Q1_1 == 1 [fweight = Freq]

        many thanks in advance for your time.

        Comment


        • #5
          It is not really clear to me whether you want to calculate the average in a given sample or estimate the mean in an underlying population. It is also unclear why you want to weigh at all. I suggest looking at mean, which allows all four weights. If you are only interested in the point estimate, then it does not matter which weight you use (except fweight, as discussed above).

          Edit: If you are not familiar with the weights that Stata supports, read [U] 20.24 Weighted estimation.
          Last edited by daniel klein; 10 Oct 2023, 08:56.

          Comment


          • #6
            I am averaging rates given by people who attend multiple events and I wanna to give more importance to people who attend only the single event I am looking at...

            Many thanks for your time Daniel, I'll follow your suggestion.

            Comment


            • #7
              asdoc does not support weights and simply ignores them. However, asdocx supports weights and complains if supplied with non-integer weights.
              Code:
              . asdoc sum price [fw=gear_ratio]
              
                  Variable |        Obs        Mean    Std. dev.       Min        Max
              -------------+---------------------------------------------------------
                     price |         74    6165.257    2949.496       3291      15906
              Click to Open File:  Myfile.doc
              
              . asdoc sum price
              
              
                  Variable |        Obs        Mean    Std. dev.       Min        Max
              -------------+---------------------------------------------------------
                     price |         74    6165.257    2949.496       3291      15906
              Click to Open File:  Myfile.doc
              
              . asdocx sum price [fw=gear_ratio]
              
              may not use noninteger frequency weights
              r(401);
              Therefore, if you are using weights, then you may like to use asdocx.
              Regards
              --------------------------------------------------
              Attaullah Shah, PhD.
              Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
              FinTechProfessor.com
              https://asdocx.com
              Check out my asdoc program, which sends outputs to MS Word.
              For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

              Comment

              Working...
              X