Announcement

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

  • Present Value Calculation of Lifetime Earnings

    Hi.
    I am trying to calculate the present value of a person's earnings given expected time s/he will live for.

    id age earnings lifeExpec discrate
    1 25 50000 50 1.017
    2 70 40000 10 1.017
    3 33 32000 28 1.017

    Since forvalues command does not take variables as maximum number for the loop, how do I calculate present value of expected lifetime earnings?

    For example, I would like to calculate the result of the following code.

    forvalues i=1/`lifeExpec' {
    egen pv = sum(earnings/(discrate)^`i')
    }

    Thanks.

  • #2
    The code you show is mistaken in many respects. But you don't even need a loop in the first place. The present value is the sum of a geometric series with lifeexpec terms and a ratio of 1/discrate. So use the formula for that:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(id age) long earnings byte lifeexpec float discrate
    1 25 50000 50 1.017
    2 70 40000 10 1.017
    3 33 32000 28 1.017
    end
    gen factor= 1/discrate
    gen pv_life_earnings = earnings*(1-factor^(lifeexpec))/(1-factor)
    Notes: If the discount rate is the same for all id's, then there is no need to waste a variable on it. Store that single valuein a scalar or local macro instead, and do the same for the variable factor that the above code creates.

    In the future, when showing data examples, please use the -dataex- command to do so, as I have here. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.


    Comment


    • #3
      The code worked perfectly. Will make sure to use dataex next time. Thanks Clyde.

      Comment

      Working...
      X