Announcement

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

  • Stata's Default Behavior With Omitting i for Categorical Variables

    Suppose we estimate
    Code:
    clear *
    cls
    //import delimited "C:\The Shop\simulated_dataset.csv"
    webuse lbw, clear
    loc iv race
    loc dv sm
    
    reg smoke i.`iv'
    reg smoke `iv'
    What is Stata's default behavior when we omit the i for the categorical variable? Does it simply interpret race, in this case, as an interval variable, where a 1 unit increase in race decreases the probability of being a smoker by 18 percentage points? I usually include the i when using categorical variables, but I've seen others not do this, and I was unsure how to interpret it.

  • #2
    Well, the i. factor-variable notation, introduced in Stata 11, is how you tell Stata that you have a categorical variable. Omitting i. is equivalent to specifying c. and tells Stata to treat the variable as continuous.


    Edit:

    To avoid misunderstandings, omitting i. is not always equivalent to specifying c. For example, using factor-variable notation to create interaction terms, such as foo##bar would treat both foo and bar as categorical by default. Here you would have to explicitly specify c. if you wanted to treat variables as continuous. More generally speaking, if you do not use factor-variable notation at all, Stata treats all variables as continuous. If you use factor-variable notation, the respective rules in [U] 11.4.3 apply.
    Last edited by daniel klein; 11 Jan 2024, 07:41.

    Comment


    • #3
      If race happens to be coded 0/1 you will get the same regression results either way. However, postestimation commands, like margins, can give you slightly different results. If race has three or more categories you will want to use factor variable notation.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      StataNow Version: 18.5 MP (2 processor)

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

      Comment

      Working...
      X