Announcement

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

  • Moving up 10 pp in the distribution and its effect

    Hi,

    Say I have three variables.
    One is grades and one is days in school, the last is id. A below:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(days id grades)
     17  1 4
     17  2 2
     17  3 4
     19  4 1
     19  5 5
     20  6 3
     34  7 3
     37  8 3
     37  9 4
     37 10 2
    160 11 5
    160 12 4
    160 13 4
    160 14 3
    160 15 2
    160 16 4
    160 17 2
    200 18 4
    200 19 4
    200 20 1
    end

    I want to show how moving up 10 percentage point in the days distribution correlates with grades. How should I approach this?

    Thanks in advance

  • #2
    Code:
    summ days
    g daysp = days/r(max)
    reg grades daysp
    margins, at(daysp = (0.1(0.1)1))
    marginsplot

    Comment


    • #3
      Originally posted by George Ford View Post
      Code:
      summ days
      g daysp = days/r(max)
      reg grades daysp
      margins, at(daysp = (0.1(0.1)1))
      marginsplot
      Thank you! If I also have a dummy variable for gender, how can I plot the margins by gender?

      Comment


      • #4
        This should get you slopes for the genders in your data at each of the requested daysp.
        Code:
        summ days
        g daysp = days/r(max)
        reg grades c.daysp##i.gender
        margins gender, at(daysp = (0.1(0.1)1))
        marginsplot
        Last edited by Erik Ruzek; 22 Jan 2024, 09:10. Reason: Added c. to daysp as per @Mike Lacy's comment

        Comment


        • #5
          Originally posted by Erik Ruzek View Post
          This should get you slopes for the genders in your data at each of the requested daysp.
          Code:
          summ days
          g daysp = days/r(max)
          reg grades daysp##i.gender
          margins gender, at(daysp = (0.1(0.1)1))
          marginsplot
          Unfortunately it is not possible to interact gender with daysp in the reg since daysp contains noninteger values. Is there any other way?

          Comment


          • #6
            Having non-integer values for a variable in no way precludes specifying that it might interact with some other variable in its effect. Figuring out how and why you came to that incorrect idea could help you now and in the future. In specifying to Stata that daysp is to be treated as a continuous variable, you'd do well to use the c prefix with it in your regression command, i.e. reg grades c.daysp##i.gender. (The c. prefix is Stata's default presumption for a factor variable, but it's good to be in the habit of being explicit.)

            Comment


            • #7
              Originally posted by Mike Lacy View Post
              Having non-integer values for a variable in no way precludes specifying that it might interact with some other variable in its effect. Figuring out how and why you came to that incorrect idea could help you now and in the future. In specifying to Stata that daysp is to be treated as a continuous variable, you'd do well to use the c prefix with it in your regression command, i.e. reg grades c.daysp##i.gender. (The c. prefix is Stata's default presumption for a factor variable, but it's good to be in the habit of being explicit.)
              Thanks, previously I ran the following line of code:
              Code:
              reg grades daysp##i.gender
              and I got the error I talked about. I guess it is necessary to include the c so Stata knows it is a continuous variable.
              Now your code works, thank you!

              Comment

              Working...
              X