Announcement

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

  • Looking for Statsby Substitute for Mixed Model with Sampling Weights

    Hello,

    I am working with the World Values Survey to run mixed-effects models in Stata 17. My unit of analysis is the individual person. There are individuals from about 100 countries. Within each country, different individuals were surveyed in different years. I want to (1) re-run the following code separately for each country in the dataset, and (2) create a new country-level variable that is the coefficient for the effect of age in each country.

    Code:
    mixed rell age [pw=S017] if country==”United Kingdom” || year:
    The following statsby command does not work for this purpose because when I try this command, I get the r(101) error message that “pweights are not supported by statsby.”

    Code:
    statsby _b, by(country): mixed rell age [pw=S017] || year:
    Are they any steps you can recommend?

    Thanks!
    Louisa

  • #2
    You can do this with:
    Code:
    capture program drop one_country
    program define one_country
        mixed rell age [pw=S017] || year:
        gen b_age = _b[age]
        exit
    end
    
    runby one_country, by(country)
    -runby- is by Robert Picard and me, and is available from SSC.

    Note: Not tested as no example data was provided. Beware of typos or other errors.

    That said, your regression model is odd; although it is legal, it is quite unusual to use year as a random effect. It would be much more common to just include i.year as a covariate in a single-level model, especially if the number of years in each country's data is small. Are you confident about this model?

    Comment


    • #3
      Dear Clyde,

      Thanks so much!! Your code worked. Runby is just what I need.

      As regards the regression model I use, that's an interesting issue. Above, I'm using a mixed-effects approach to model religiosity. My understanding is that the random effect for year (which I use above) allows the model's intercept to vary randomly across the different years in which the country was surveyed. I believe this is similar to controlling for the effect of year using i.year, the only difference being that my mixed-effects model gives slightly greater weight to the information from years in which there were a larger number of survey respondents.

      Louisa

      Comment


      • #4
        I believe this is similar to controlling for the effect of year using i.year, the only difference being that my mixed-effects model gives slightly greater weight to the information from years in which there were a larger number of survey respondents.
        It is similar, but not the same. In the random effects model underlying -mixed-, the assumption is that the yearly intercepts are sampled from a normal distribution. It is also assumed that the yearly intercepts are independent of both rell and age. By contrast, when you use i.year, the yearly intercepts are completely unconstrained: they can be anything at all. If the assumptions underlying -mixed- are true (or close enough to true) then -mixed- provides more efficient estimates of the parameters. The normality assumption is difficult to test, and, in any case, the results are reasonably robust to departures from normality, at least in large samples. But the independence from rell and age is inherently untestable, and generally speaking can only be relied upon in data from a randomized experiment or in data where an adequate number of covariates have been included so that the likelihood of residual confounding has been minimized. Your situation meets neither of these descriptions. But if the assumptions are not true, then the estimates are inconsistent and the use of i.year would be appreciably better.

        Comment

        Working...
        X