Announcement

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

  • value weighted average beta calc

    Dear all,

    I have a database with mutual fund data, for each month there are many funds and each of these funds has different stock holdings (number of shares*price) and each stock has as well the respective beta. I need to calculate for each month for each fund this value weighted average beta based on these holdings. I have come up with the commands as below, can anyone let me know whether its okay, or do i need to consider anything else?


    bys fundid month_id: gen beta= sum(beta*price*numbershares)/sum(((beta)!=.)*numbershares*price)
    bys fundid month_id: replace beta= Beta [_N]

    Thanks in advance,

  • #2
    You'll increase your chances of a useful answer by following the FAQ on asking questions – provide Stata code in code delimiters, readable Stata output, and sample data using dataex. We are mainly not from your area, so telling us exactly what you want to calculate would help.

    If you're just starting with Stata, you might want to break your generate into pieces for debugging.

    You can use egen with total instead of generate with sum to get your totals and not need the second statement.

    g value=price * numshares
    g wtbeta1=beta * value
    egen sumvalue=total(value) if beta !=.
    egen sumwtbeta=total(wtbeta1)
    g wtbeta= sumwtbeta/sumvalue

    You will also find it less confusing to give new variables new names. You have beta defined as two different things in your two lines. This invites confusion.

    Comment

    Working...
    X