Announcement

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

  • Creating Percent Change Variable

    Hello,

    I am doing a secondary data analysis of pre and post-surveys for a falls prevention program. There are 427 pre and post surveys, and each pre- and post-survey notes the # of times fallen in the past three months. I am trying to create a % change variable for each observation based on the TimesFallen_pre and TimesFallen_post variables.

    I tried creating the variable by using this code:
    gen ReducFalls_percent = (TimesFallen_post - TimesFallen_pre)/TimesFallen_pre

    However, I the result is 417 missing values. Many of the participants recorded 0 falls on the pre-survey and 0 falls on the post-survey, so I think my issue is that 0 is being treated as missing? Or the gen command won't divide by 0?

    If someone could please help me figure out the correct code to create a % change variable for each observation, that would be awesome.

    Thank you

  • #2
    Division by zero in Stata yields missing. This is the equivalent of school mathematics teaching, which may have been some variation on "you can't divide byzero" or "the result of dividing by zero is undefined or indeterminate". Stata is not being perverse or lacking here: it is just following mathematical principles.

    More positively, you can decide if it makes sense that 0 to 0 also qualifies as a 0 proportional change (your results are not percents):

    Code:
    replace ReducFalls_percent = 0 if  TimesFallen_post = 0  & TimesFallen_pre == 0

    Comment


    • #3
      See also Stata's function reldif().

      Comment

      Working...
      X