Announcement

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

  • Boostrapping a relative difference with confidence bounds

    Dear All,

    I have used the search function on STATAlist but have not found a solution to my problem.
    I want to bootstrap relative difference to calculate a mean relative difference with confidence bounds. I am assuming that nlcom can get me here, but have so far not been able to do it. Does anybody have any experience with this? Any suggestions would be more than helpful!

    Thank you all.

    Best,

    Jasper

  • #2
    At least for me, "mean relative difference" does not have a precise meaning. That is, it might simply reference (ybar1 - ybar2)/(ybar1), where ybar1 and ybar2 are sample means from independent groups. If that is correct--which I suspect it isn't--this could be done like this:
    Code:
    cap prog drop reldiff
    prog refdiff, rclass
    // y is the variable of interest, group is the variable identifying the groups to be compared, and
    // val1 and val2 are the values of group defining the comparison
    args y val1 val2 group
    summ `y'  if `group' == `v1', meanonly
    local mean1 = r(mean)
    summ `y'  if `group' == `v2', meanonly
    local mean2 = r(mean)
    return scalar mrd =  (`mean1' - `mean2'/`mean1')
    end
    //
    bootstrap r(mrd), reps(1000): reldiff YourY  YourV1 YourV2 YourGroup
    However, I suspect (from a bit of searching) that "mean relative difference" has differing and distinct meanings depending on the disciplinary context, so perhaps you want something else.

    Comment


    • #3
      Dear Mike,

      Thank you so much for your very complete answer. I have a variable of interest (age) and a group variable (sex) defined as male (0) and female (1).

      The goal is to create a graph as attached (Sanders-vanWijk et al. Eur J HF 2015), which I feel is an eloquent way to show relative differences in means between two groups. Would your suggestion work for my problem? Thank you.
      Click image for larger version

Name:	final.jpg
Views:	1
Size:	32.4 KB
ID:	1376814

      Comment


      • #4
        Your graph does not display readably online. Further, there's no indication of what horizontal axis indicates, what the structure of your data is, and so forth. This makes it quite hard for anyone to help you. In any event, I'm not much of a graph user, so I won't be of any particular help.

        Comment


        • #5
          Dear Mike,

          Thank you very much for your help. I am terribly sorry if the graph is not readable and I am also not trying to cause confusion here. I used this graph to illustrate a final results which I am working towards, coding the graph is no problem for me luckily.

          Going back to the question at hand, I have a continuous variable (age) and a group variable (sex) defined as male (0) and female (1). Would your suggestion work for calculating the bootstrapped mean age difference with confidence bounds between in this case males and females? I really appreciate your thoughts.

          Best,

          Jasper

          Comment


          • #6
            Jasper:
            as per FAQ, you should have provided the full reference of the article you mentioned (by chance, I know it): http://onlinelibrary.wiley.com/doi/1.../ejhf.414/epdf.
            The graph is hardly readable in the original article, though.
            That said, I'm still not clear with what you're after: are -sex and -age- the predictors of a regression with a (for us) unknown dependent variable? Are you going to calculate the mean of age stratified by sex? Else?
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Dear Carlo,

              Thank you for informing me of my error, I will definitely keep it in mind for future posts.

              What I am specifically looking for is the relative "percentage" difference in age of women versus age in men with a 95% confidence interval. So the results would be a bootstrapped % difference in mean age of women (coded as 1) with a 95%CI with men (coded as 0) as the reference group.

              Taking Mike's wonderful suggestion, I adjusted it to my needs and came up with the following:

              Code:
               cap prog drop reldiff
              program reldiff, rclass
              summ age  if sex == 1, meanonly
              local mean1 = r(mean)
              summ age  if sex == 0, meanonly
              local mean2 = r(mean)
              return scalar mrd =  ((`mean1' - `mean2')/`mean1')
              end
              //
              bootstrap r(mrd), reps(1000): reldiff
              Very keen to hear your thoughts and comments.
              Last edited by Jasper Tromp; 04 Mar 2017, 10:11.

              Comment


              • #8
                Jasper:
                you can top off your code with the bootstrap 95% CI.
                Take a look at -bootstrap- entry in Stata .PDF manual.
                Kind regards,
                Carlo
                (Stata 19.0)

                Comment

                Working...
                X