Announcement

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

  • stratified linear regressions

    (posted on behalf of my colleague Mylene):

    Hello
    I am a graduate student in the USA and new-ish to Stata, working on my masters in Psychology using Stata to help analyze my data.

    I have run a series of univariable regressions of 10 different variables, both ordinal and continuous, on my main dependent variable of interest: l_score
    Sex was found to be significant and is known, a priori, to associate with l_score and possibly be an effect modifier of other variables of interest, on l_score.

    I am wondering if it is possible to stratify all my univariable regressions by sex? How might I do this?

    And then also, if I am trying to examine the interaction between sex and other variables (let's say "g_score") on "l_score" would I run the following code?

    regress l_score sex g_score sex#g_score


    Thanks so much for any help
    Best wishes
    Mylene




    Last edited by Alan Jeddi; 04 Jul 2018, 13:53.

  • #2
    Hello Alan & Mylene. Type help factor variables (or help fvvarlist) in the Command window for relevant information. Notice that when using # and ##, the default is to treat the variables as categorical. If your g_score variable is (to be treated as) quantitative, you'll have to use the c. prefix. Also, regress treats explanatory variables as quantitative by default. So you must use the i. prefix for any categorical explanatory variables. Assuming you want to treat sex as categorical and g_score as quantitative, you could do any of the following--they should all yield the same results.

    Code:
    regress l_score i.sex c.g_score i.sex#c.g_score // use # and be explicit about all variables
    regress l_score i.sex   g_score   sex#c.g_score // use # and rely on defaults
    
    regress l_score i.sex##c.g_score // use ## and be explicit about all variables
    regress l_score   sex##c.g_score // use ## and rely on defaults
    And the following margins command (executed immediately after regress) should give you the simple slopes for males & females.

    Code:
    margins, dydx(g_score) over(sex)
    HTH.

    Last edited by Bruce Weaver; 04 Jul 2018, 16:01. Reason: Added the -margins- command to show simple slopes.
    --
    Bruce Weaver
    Email: [email protected]
    Version: Stata/MP 18.5 (Windows)

    Comment


    • #3
      Originally posted by Bruce Weaver View Post
      Hello Alan & Mylene. Type help factor variables (or help fvvarlist) in the Command window for relevant information. Notice that when using # and ##, the default is to treat the variables as categorical. If your g_score variable is (to be treated as) quantitative, you'll have to use the c. prefix. Also, regress treats explanatory variables as quantitative by default. So you must use the i. prefix for any categorical explanatory variables. Assuming you want to treat sex as categorical and g_score as quantitative, you could do any of the following--they should all yield the same results.

      Code:
      regress l_score i.sex c.g_score i.sex#c.g_score // use # and be explicit about all variables
      regress l_score i.sex g_score sex#c.g_score // use # and rely on defaults
      
      regress l_score i.sex##c.g_score // use ## and be explicit about all variables
      regress l_score sex##c.g_score // use ## and rely on defaults
      And the following margins command (executed immediately after regress) should give you the simple slopes for males & females.

      Code:
      margins, dydx(g_score) over(sex)
      HTH.
      Hi Mr Weaver,
      Thank you very much; this is very helpful!!
      Is running an interaction using the code:
      regress l_score i.sex##c.g_score
      the same a stratifying by my results by sex?

      I am trying to do both of the following
      a) present each of my univariable regressions of a given variable on l_score stratified by sex
      b) evaluate the interaction between each variable and sex (ie, see if the relationship between I_score and other IVs is different at different 'levels' of sex)

      Thank you again for your help and support!
      Mylene & Alan


      Comment


      • #4
        Hello Mylene & Alan. The following code gives everything you want, I think.

        Code:
        regress l_score i.sex##c.g_score
        margins, dydx(g_score) over(sex)
        The margins command will give you estimates of the population slopes for males & females separately. In the output from regress, the coefficient for the interaction term estimates the difference between the population slopes for males & females; and the t-test for that coefficient tests the null hypothesis that there is no difference between the population slopes.

        HTH.
        --
        Bruce Weaver
        Email: [email protected]
        Version: Stata/MP 18.5 (Windows)

        Comment

        Working...
        X