Announcement

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

  • mixed command with same variable defined as both fixed effect and random effect

    I used the mixed command and defined country_code as both fixed effects (.country_code) and random effect (||country_code: ). Stata dealt with it and provided an output with both coefficients for the i.country_code and for the random effect parameter country_code. Does this make sense? thank you

  • #2
    No, it does not make sense, unless your "random effect parameter country_code" was coded as - || random_level: i.country_code -. (If you are using an old version of Stata that does not allow i. in the random effects part of -mixed-, then look into the old, otherwise obsolete, -xi- command.)

    The problem is that if you coded it without the i. in the random level, then there it is treated as a continuous variable, whereas in the fixed part where you coded it with the i. it is treated as a discrete variable. If the variable country_code is what its name suggests, namely some arbitrary set of numbers distinguishing different countries, its use as a continuous variable makes no sense in any context. If somehow country_code is, instead, a poor choice of names for a real continuous variable like GDP, then its use with i. is usually (though not always) inappropriate. Even when you have one of the unusual situations where it can be sensible to use i. with a continuous variable, you can't be inconsistent about it within a single command. And in particular, with -mixed- it is important that any variable for which you designate a random slope must also appear in the fixed part of the command so that the distribution of slopes for the variable will not be arbitrarily constrained to have mean zero.

    In general, the use of any variable with an i. in one place and without i. in the same command leads to nonsense code. There are a few exceptions where it works out ok, but it is easier to just get into the habit of using i. consistently than to learn and attempt to apply the handful of situations where you can get away with mixing them.

    In the future, when asking for help with code, it is better to show the complete actual command(s) you are asking about as well as the complete actual output that Stata gave you. That way you won't get a convoluted response explaining the implications if you did this, that, or the other thing.

    Comment


    • #3
      Clyde’s advice is excellent as usual.

      In the chance that you instead wanted a country level random intercept, which is what the syntax snippet suggested, then you want - || country_code : - in the mixed model but not -i.country_code- in the fixed effects portion. The reason is that they are treating the estimation of country code effect in two very different ways (explicit estimation vs assuming a normal distribution).

      Comment


      • #4
        Thank you very much, Clyde and Leonardo.

        The variable: country_code is some arbitrary set of numbers distinguishing different countries.
        So would the following code (which is meant to have a country level random intercept) be OK?

        mixed f_borr WoB i.year || country_code: ||ID: , vce(cluster country_code )

        f_borr is a continous variable as is WoB. year, is a set of numbers for each year. country_code and ID are two sets of
        some arbitrary numbers distinguishing different countries and organizations, respectively. (ID is nested within country_code)

        Comment


        • #5
          Yes, that code does what you say you want.

          Comment


          • #6
            thank you very much, Clyde.

            Comment

            Working...
            X