Announcement

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

  • Adding interactions using factor variables

    Hello!
    I am trying to add some interactions to my regression model in order to control for some characteristics of the sample.

    I am having some troubles in understanding which is the difference between using i.state#age and i.state#c.age. I had a look at help fvvarlist in order to understand the difference but I am still doubtful. Using c.age, I am considering it as a continuous variable, but so, what does it mean to use age? Is it not continuous too?

    Thank you for your answers

  • #2
    Hello Alessandro, welcome to the Stata Forum.

    Under - regress - (you didn't underline the command, but I assume that it is "regress"), variables are taken as continuous, unless we use factor notation. With regards to your query on interaction terms, the degrees of freedom are something to take into account.

    Best,

    Marcos
    Best regards,

    Marcos

    Comment


    • #3
      writing a variable in an interaction without the leading "c." will have treated as a factor variable - did you actually try it?

      Comment


      • #4
        Originally posted by Marcos Almeida View Post
        Hello Alessandro, welcome to the Stata Forum.

        Under - regress - (you didn't underline the command, but I assume that it is "regress"), variables are taken as continuous, unless we use factor notation. With regards to your query on interaction terms, the degrees of freedom are something to take into account.

        Best,

        Marcos
        Sorry, I should have specified. Yes, I am running a regression using "regress". Ok, I am aware of that but so what is the point in using c. in constructing interaction terms?

        writing a variable in an interaction without the leading "c." will have treated as a factor variable - did you actually try it?
        Yes, I have tried and I have obtained what I expected, i.e. a series of intercations where both state and year were factor variables and I think that's what I actually need. But, as I asked to Marcos, what's the point in using c. (I have seen an example in fvvarlist help file that made me confused).

        Thanks to both for your answers

        Comment


        • #5
          What is the point in using the c. operator? As stated, without it, you get a series of indicator variables instead of treating the variable as continuous. Which one you want depends on the situation. Note that, in any case, you must include the lower order terms in the model.

          Code:
          sysuse auto
          
          /*
              not using c. treats mpg as categorical */
          regress price i.foreign##mpg
          
          /*
              the c. operator specifies that mpg is continuous */
          regress price i.foreign##c.mpg
          The key to the understanding here is probably that in

          Code:
          regress price mpg foreign
          both, mpg and foreign, are treated as continuous, which is the default if you do not use factor variable notation. Typing

          Code:
          regress price mpg##foreign
          treats both, mpg and foreign, as categorical, the default if factor variable notation is used. Think of the above as

          Code:
          regress price i.mpg##i.foreign
          where you may omit the i. prefix.

          That is, the default treatment of variables depends on whether they are used in factor variable notation or not.

          Best
          Daniel
          Last edited by daniel klein; 22 Jun 2016, 04:36.

          Comment


          • #6
            The c. is used when you want to treat that variable as continuous. So that way you can use the factor variable notation for interactions between one or more continuous variables. Since you seem to want to treat your variables as categorical, you should not use it.
            ---------------------------------
            Maarten L. Buis
            University of Konstanz
            Department of history and sociology
            box 40
            78457 Konstanz
            Germany
            http://www.maartenbuis.nl
            ---------------------------------

            Comment

            Working...
            X