Announcement

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

  • line graph the ratio of means by a bicategorial variable for different regions over time

    I want to create a line graph that shows the ratio of means of numerical variable(wage) by a bicategorial variable(sex) for different regions over time. So for example in year x in region y the ratio (male wage/female wage).

    collapse (mean) wage = p_wage, by(year sex region)

    by year sex region, sort: gen wage_m= wage if sex==1
    by year sex region, sort: gen wage_f = wage if sex==2

    by year sex region, sort: gen wage_ratio= (wage_m/wage_f)

    twoway line wage_ratio year if region==1 ///
    || line wage_ratio year if region==2 ///
    etc.

    The graph comes up empty. Apparently I cant create the variables in the ways needed so that stata understands. What am I doing wrong?

  • #2
    The ratio calculation fails because the means for males are missing when the means for females are defined, and conversely.

    There is no data example here, but a guess at code is possible.

    Code:
    collapse (mean) wage = p_wage, by(year sex region)
    
    bysort year region (sex): gen wage_ratio = wage[1]/wage[2]
    
    twoway line wage_ratio year if region==1 || line wage_ratio year if region==2

    Comment


    • #3
      Thanks Nick it works. I was aware that Stata couldnt produce the ratio as I wanted because when I tried to tab it it wouldnt show any values. I didnt know about the ...[1]/...[2] style. It didnt work using if ^^.

      Comment

      Working...
      X