Announcement

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

  • Coding interaction variables

    I am fitting a model that includes a long list of interactions like i.x##c.y i.x##c.y2 i.x##i.z##i.q
    That's fine if I'm using a command that can handle the ## coding, but what if I'm not?
    Is there a quick way to code up all the interactions as a list of dummy variables, and then put that list in a macro variable that I can use wherever I like?

    Many thanks for suggestions.

  • #2
    the first place to look is at the old -xi- command; start with -h xi-; if that doesn't do what you want post again including why it doesn't fit - rich

    Comment


    • #3
      Very good! I only knew xi as a prefix. I didn't realize it was also a standalone command.

      Comment


      • #4
        Remember too that if the estimation command does not support the xi prefix, you can also use xi as a command to create variables.
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        StataNow Version: 18.5 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment


        • #5
          The xi command almost solves the problem. The remaining problem is that xi creates variables of the form
          _I<stub>_<groupid>
          where <stub> is only 3 characters. This causes problems for since some of my variables are indistinguishable if only the first 3 characters are used. For example, the following command produce identically named _I* variables:

          xi i.year*PercentED
          xi i.year*PercentED2

          Any suggestions most welcome.

          Comment


          • #6
            Maybe fvrevar can help? Best Daniel

            Comment


            • #7
              Unfortunately fvrevar doesn't help because the command I'm using (xtivreg2) doesn't support factor variables.

              Comment


              • #8
                I'm now having a new problem where the results of one xi command don't persist after I run another xi command. For example, below I successfully make dummies for 7th & 8th grade, but they disappear after I make dummies for years.

                . xi i.Grade
                i.Grade _IGrade_6-8 (naturally coded; _IGrade_6 omitted)

                . summarize _IGrade*

                Variable | Obs Mean Std. Dev. Min Max
                -------------+--------------------------------------------------------
                _IGrade_7 | 28155 .3581602 .4794681 0 1
                _IGrade_8 | 28155 .357805 .4793629 0 1

                . xi i.year
                i.year _Iyear_2008-2011 (naturally coded; _Iyear_2008 omitted)

                . summarize _IGrade*
                variable _IGrade* not found

                Comment


                • #9
                  This is documented behaviour.

                  When you use xi, it drops all previously created interaction variables starting with the prefix specified in the prefix(string) option or with _I by default.
                  Therefore, if you want to keep the variables with a certain prefix, specify a different prefix in the prefix(string) option.

                  Comment


                  • #10
                    Regarding my problem with running two successive xi commands, I found that the problem went away if I combined them into a single command: "xi i.Grade i.year".
                    I don't know why that fixed the problem, but it did.

                    Comment


                    • #11
                      Unfortunately fvrevar doesn't help because the command I'm using (xtivreg2) doesn't support factor variables.
                      But this is exactly the type of situation fvrevar is intended for. It does however not solve your problem with the variable names. Actually, the variable names may even be worse as you may only specify a stub for them.

                      Best
                      Daniel

                      Comment

                      Working...
                      X