Announcement

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

  • SAS code to Stata (REML ARMA (1,1))

    I am trying to move existing analysis on SAS to Stata,

    The following SAS code is what I hope to rewrite into Stata code:

    proc mixed data=dt1 covtest;* CONVH=1e-6;
    class gvkey grp year grp_dvrd SIC;
    model DV= gvkey(SIC) year var1|grp|var2 var3 var4|grp/s ddfm=sat ;
    repeated year / subject=gvkey type=arma(1,1) group=SIC;

    I think this should involve XTMIXED on stata, but I'm having trouble replicating the same analysis with "repeated year / subject=gvkey type=arma(1,1) group=SIC;"
    Any help understanding the above SAS code or translating it to Stata code would be greatly appreciated!
    Thank you so much in advance.

  • #2
    Francis,

    Unless you are using an older version of Stata, the command is -mixed-, not -xtmixed-.



    In SAS, the repeated statement appears to refer to the specification for the residuals. I have no idea why the variable year was explicitly specified in the -repeated- statement. Per the manual,

    Specifying a repeated effect is useful when you do not want to indicate missing values with periods in the input data set. The repeated effect must contain only classification variables. Make sure that the levels of the repeated effect are different for each observation within a subject; otherwise, PROC MIXED constructs identical rows in corresponding to the observations with the same level. This results in a singular and an infinite likelihood.
    (Where R is the residual matrix, I think.) I am going to ignore the year bit. Here are the bits I think I understand.

    Code:
    type = arma(1,1)
    refers to the residual structure, I'm unfamiliar with ARMA structures. Stata allows for autoregressive and moving average specifications, but I don't see an explicit ARMA specification.

    Code:
    subject = gvkey
    appears to specify which is a unique group of observations. These can be individual subjects, obviously. There's no parallel option in Stata, and you specify this bit differently.

    Code:
    group = SIC
    means calculate residuals by unique levels of SIC, which you defined as a classification variable, and which we would call a factor variable in Stata.

    I think the syntax you want is something like:

    Code:
    mixed DV i.gvkey##i.SIC i.year c.var1#c.grplvar2 var3 c.var4##i.grp || gvkey:, sattherthwaite residuals(ma 1, by(SIC) t(year))
    I am totally confused at how SAS specifies interactions. This is how we do it in Stata. Beware of blindly copying my specification of your model.

    Also, it's unclear to me if your model specifies a random slope. If you want a random slope with time specified as continuous, you type:
    Code:
    mixed DV i.gvkey##i.SIC i.year c.var1#c.grplvar2 var3 c.var4##i.grp || gvkey: year, sattherthwaite residuals(ma 1, by(SIC) t(year))
    Or if you want a random effect for year treated as categorical, I think you type R.year.
    Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

    When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

    Comment


    • #3
      Thank you so much for the detailed explanations! I will try to work with this on Stata and follow up on the results.

      Comment


      • #4
        i have the same problem with Francis. In SAS, I can model the residuals as ARMA (1,1) for a panel data set. However I cannot find the equivalent ARMA (1,1) code in Stata. In Stata, I can either use residuals (ar 1, t()) or residuals (ma 1, t()) but can never combine them as (arma(1,1), t()). Who can help on this, please?

        Comment


        • #5
          I can't really help, as I am unfamiliar with the concepts behind time series analysis. All I would add is this: Remember that in a mixed model, the random intercept should already account for a lot of what might otherwise appear to be an autoregressive pattern in Y, your outcome variable. The discussion above pertains to the residual structure, so you are asserting that after controlling for every observed characteristic, you expect the residuals of the model to have an autoregressive, moving average, or autoregressive moving average structure (pardon me if I've used the wrong terminology). So, first, do you need a residual structure? If yes, can you get by with just autoregressive or moving average residual specifications? Does your analysis become invalid if you can't model it as autoregressive moving average?

          Now, on to correct a probable error on my part:

          Originally posted by Weiwen Ng View Post
          ...
          Code:
          mixed DV i.gvkey##i.SIC i.year c.var1#c.grplvar2 var3 c.var4##i.grp || gvkey: year, sattherthwaite residuals(ma 1, by(SIC) t(year))
          ...
          In the above code, I was trying to replicate what I thought the SAS code was saying. I don't think you can specify an interaction effect without its corresponding main effects. So, there should be a main effect for var1 and grplvar2 in the model. The model, as I typed it, only has var1 interacted with grplvar2. I apologize for the error. If the original SAS code implied that you should do that, then I believe the original code is incorrect.
          Last edited by Weiwen Ng; 31 Jul 2018, 13:35.
          Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

          When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

          Comment


          • #6
            Thanks for the quick response, Weiwen! I further did some readings today and realized that actually across all the software on the market, it seems that only R and SAS can possibly allow you to model the residual structure as arma (1,1). I think what you have described is right. My problem is that in my field, lots of reviewers (who normally use SAS) will push back asking to use arma (1,1) to model residuals as a robustness check. I think now, as a Stata user, the problem for me is how to push back to convince them that separate AR 1 or MA 1 robustness check should also work!

            Comment


            • #7
              Another note to Francis: I can only help on the arma (1,1) part. I am now very confident to say that for a mixed effect model in Stata, for residuals, you can either do ar 1 or ma1, there is just no built in algorithm for arma (1,1).

              Comment


              • #8
                Originally posted by Wayne Kay View Post
                it seems that only R and SAS can possibly allow you to model the residual structure as arma (1,1)
                Have you looked into modeling the residuals in gsem using a couple of latent factors for the two parameters of the ARMA(1, 1) residual correlation structure? The model would start out like a conventional SEM latent growth model, but with a couple of additional thingies connecting the residuals (and maybe some constraints on them) in order to impose the structure that you desire.

                You won't be able to get a REML model fit, however, that you would get with SAS's PROC MIXED. If only mixed allowed constraints, you might be able to do look into something analogous with it.

                Comment


                • #9
                  Originally posted by Joseph Coveney View Post
                  Have you looked into modeling the residuals in gsem using a couple of latent factors for the two parameters of the ARMA(1, 1) residual correlation structure? The model would start out like a conventional SEM latent growth model, but with a couple of additional thingies connecting the residuals (and maybe some constraints on them) in order to impose the structure that you desire.

                  You won't be able to get a REML model fit, however, that you would get with SAS's PROC MIXED. If only mixed allowed constraints, you might be able to do look into something analogous with it.
                  Thanks Joseph for your reply. I think your logic makes sense. I'll try it out.

                  Comment

                  Working...
                  X