Announcement

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

  • Compute a difference rate between two variables

    Hello everyone,

    I have to use the variables lonely and ca_couple, calculate the proportions of individuals who feel lonely some of the time or often separately by whether they are living with a partner or not.

    Then, I need to calculate the difference in the rate of "loneliness" between those two groups.
    • lonely takes 1 if the individual feels lonely sometimes or often. And 0 if the individual hardly ever or never feels lonely.
    • ca_couple takes 1 if living in couple, and 0 otherwise.
    I tried the follwowing code:
    Code:
    tabulate lonely ca_couple, row col
    local p_lonely_couple = 100*r(row1col1)/r(row1col2)
    local p_lonely_single = 100*r(row2col1)/r(row2col2)
    local diff_lonely = `p_lonely_single' - `p_lonely_couple'
    display "Difference in the rate of loneliness: " %5.2f `diff_lonely'
    Is a better way to do that? Thank you in advance. I obtain that in stata:

    Code:
    . local p_lonely_couple = 100*r(row1col1)/r(row1col2)
    
    . local p_lonely_single = 100*r(row2col1)/r(row2col2)
    
    . local diff_lonely = `p_lonely_single' - `p_lonely_couple'
    
    . display "Difference in the rate of loneliness: " %5.2f `diff_lonely'
    Difference in the rate of loneliness:     .
    Best,

    Michael
    Last edited by Michael Duarte Goncalves; 24 Mar 2023, 01:33.

  • #2
    Originally posted by Michael Duarte Goncalves View Post
    . . . I need to calculate the difference in the rate of "loneliness" between those two groups.
    . . . Is a better way to do that?
    Code:
    regress lonely i.ca_couple
    The regression coefficient is the difference in proportions of lonely between the two categories of couple.

    If you want some kind of test statistic for it and if your sample size is more than just a handful, then try something like the following.
    Code:
    glm lonely i.ca_couple, family(binomial) link(identity)

    Comment


    • #3
      Hello Joseph Coveney ,

      Thanks a lot!

      Michael

      Comment


      • #4
        Reverting to #1 r(row1col1) and its siblings are guesses at what you would like to exist. It is not an error to refer to an r-class result that is not defined, but the result is missing, which contaminates all later calculations. Hence the code in #1 did not evoke any syntax errors, but that is why the code did not work.

        It's rare (although not impossible) that r-class results that are defined are not documented. So, whatever is not documented is unlikely to exist.

        Comment


        • #5
          Thank you for the explanation Nick.
          All is clear now.

          Michael

          Comment

          Working...
          X