Announcement

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

  • Multiply variable values by their frequencies

    Dear all,

    I don't seem to find a way (other than do it manually) to multiply a variable's values (numeric) by their frequencies. The variable at stake is the count/occurrence of an event, and it looks like (a simplified version of it):
    V1 Freq.
    3 2
    4 1
    6 3
    8 1
    Total 7
    The event captured by var. V1 occurs in different localities and across different social groups (I have separate variables for both "locality" and "group"). Since var. V1 captures occurrences, the "real" total of occurrences isn't 7 as reported by a simply tabulation, but 36 (3*2+4*1+6*3+8*1). The real dataset is much bigger, so doing this manually isn't ideal, even more so when taking into consideration "locality" and "group."

    I was wondering if there's a simple way to achieve these multiplications of each variable value by its frequency. Please let me know if my question isn't properly explained, I'd be happy to give more details. Thank you.
    Last edited by Yuji Shimohira; 18 Nov 2017, 05:58. Reason: Simplified the way I originally posed my question.

  • #2
    Although your table above might suggest you have "freq" as a variable, I suspect you don't, in which case:
    Code:
    bysort V1: gen V1Xfreq = V1 * _N
    will create a variable, which you can tabulate.

    Comment


    • #3
      Thank you, Mike. The table in OP was a reproduction of:

      Code:
      tab V1
      Your suggestion is very helpful. When checking the frequencies of V1 by other variable I ended up using:

      Code:
      graph dot (rawsum) V1, over(someothervar)
      which I think does the job.

      Comment

      X