Announcement

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

  • How to deal with categorical variable (a group of dummy vars) in Multilevel model?

    Hi there,

    I'm working on a dataset with individual-level and school-level variables using multilevel model. The independent variable is a categorical variable (with four categories) which is transformed to three dummy variables.

    Code:
    mixed PV1MATH ESCS male i.gr9 i.gr1011 i.c1p_sg1 i.c2p_sg1 i.cc_fg1 ///
    immiage ltt ESCSave IMMIrate||CNTSCHID:
    That works.

    But when I tried to test the random effect of school-level variables on these dummy variables' slops, there were always some errors:

    First, the code is like this:
    Code:
    mixed PV1MATH ESCS male i.gr9 i.gr1011 i.c1p_sg1 i.c2p_sg1 i.cc_fg1 ///
    immiage ltt ESCSave IMMIrate||CNTSCHID: i.c1p_sg1 i.c2p_sg1 i.cc_fg1
    Then Stata told me that
    must use R. when specifying factor variables in random-effects equations
    Then I tried:
    Code:
        mixed PV1MATH ESCS male i.gr9 i.gr1011 i.c1p_sg1 i.c2p_sg1 i.cc_fg1 ///
        immiage ltt ESCSave IMMIrate||CNTSCHID: R.c1p_sg1 R.c2p_sg1 R.cc_fg1
    Stata said:
    R.c1p_sg1 R.c2p_sg1 R.cc_fg1 invalid level specification
    Then I typed:
    Code:
    mixed PV1MATH ESCS male i.gr9 i.gr1011 i.c1p_sg1 i.c2p_sg1 i.cc_fg1 ///
        immiage ltt ESCSave IMMIrate||CNTSCHID: c1p_sg1 c2p_sg1 cc_fg1, cov (un)
    Stata told me that
    Warning: standard-error calculation failed
    Then I tried:
    Code:
    mixed PV1MATH ESCS male i.gr9 i.gr1011 i.c1p_sg1 i.c2p_sg1 i.cc_fg1 ///
        immiage ltt ESCSave IMMIrate||CNTSCHID: c1p_sg1 c2p_sg1 cc_fg1
    Stata gives a result but no standard errors:
    Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
    -----------------------------+------------------------------------------------
    CNTSCHID: Independent |
    var(c1p_sg1) | 549.0446 . . .
    var(c2p_sg1) | .00066 . . .
    var(cc_fg1) | 3.43e-13 . . .
    var(_cons) | 1068.627 . . .
    -----------------------------+------------------------------------------------
    var(Residual) | 4851.256 . . .
    ------------------------------------------------------------------------------
    LR test vs. linear model: chi2(4) = 601.67 Prob > chi2 = 0.0000

    I want to know why that happens and how to deal with these problems.

    Also, I have to admit that I don't know much about the principle of how multilevel model deals with dummy variables and I should have understood. Could you please also recommend some books or papers if you know any reference for related issues?

    Thank you very much.







  • #2
    Vincent:
    welcome to this forum.
    The first step to take is taking a look at -fvvarlist- help file and related entry in Stata .pdf manual.
    Then go to -mixed- entry, same source.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Originally posted by Carlo Lazzaro View Post
      Vincent:
      welcome to this forum.
      The first step to take is taking a look at -fvvarlist- help file and related entry in Stata .pdf manual.
      Then go to -mixed- entry, same source.
      Thanks Carlo.
      I learned the help documents and I think, in the fixed part, the dummy vars should be i.var1 i.var2 i.var3, in the random part, they should be var1 var2 var3 (the code is as follow). And the important thing is to determine the vartype related to covariance matrix. Is it a right direction to solve the problem?
      Code:
       
       mixed PV1MATH ESCS male i.gr9 i.gr1011 i.c1p_sg1 i.c2p_sg1 i.cc_fg1 ///     immiage ltt ESCSave IMMIrate||CNTSCHID: c1p_sg1 c2p_sg1 cc_fg1, cov(vartype)

      Comment


      • #4
        Vincent:
        the choice of -vartype- option mostly depends on your data, your research goal and, least but not least (especilly if you plan to submit a paper concerning your reserach to a technical journal) on what is considered usual in yiour research field.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Originally posted by Carlo Lazzaro View Post
          Vincent:
          the choice of -vartype- option mostly depends on your data, your research goal and, least but not least (especilly if you plan to submit a paper concerning your reserach to a technical journal) on what is considered usual in yiour research field.
          Thanks Carlo.
          One more question, why can not standard error be calculated when the -vartype- is independent?
          Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
          -----------------------------+------------------------------------------------
          CNTSCHID: Independent |
          var(c1p_sg1) | 549.0446 . . .
          var(c2p_sg1) | .00066 . . .
          var(cc_fg1) | 3.43e-13 . . .
          var(_cons) | 1068.627 . . .
          -----------------------------+------------------------------------------------
          var(Residual) | 4851.256 . . .
          ------------------------------------------------------------------------------
          LR test vs. linear model: chi2(4) = 601.67 Prob > chi2 = 0.0000

          Comment


          • #6
            Vincent:
            please provide what you typed and what Stata gave you back (as per FAQ). Thanks.
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Originally posted by Carlo Lazzaro View Post
              Vincent:
              please provide what you typed and what Stata gave you back (as per FAQ). Thanks.
              Thanks Carlo.
              Code and feedback are as follows:


              Code:
              Code:
               
               mixed PV1MATH ESCS male i.gr9 i.gr1011 i.c1p_sg1 i.c2p_sg1 i.cc_fg1 ///     immiage ltt ESCSave IMMIrate||CNTSCHID: c1p_sg1 c2p_sg1 cc_fg1
              ​​​​​​​
              Stata gives a result but no standard errors:
              Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
              -----------------------------+------------------------------------------------
              CNTSCHID: Independent |
              var(c1p_sg1) | 549.0446 . . .
              var(c2p_sg1) | .00066 . . .
              var(cc_fg1) | 3.43e-13 . . .
              var(_cons) | 1068.627 . . .
              -----------------------------+------------------------------------------------
              var(Residual) | 4851.256 . . .
              ------------------------------------------------------------------------------
              LR test vs. linear model: chi2(4) = 601.67 Prob > chi2 = 0.0000

              Comment


              • #8
                Vincent:
                it would seem that you do not have a panel-wise effect in your dataset.
                Kind regards,
                Carlo
                (Stata 19.0)

                Comment

                Working...
                X