Announcement

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

  • Factoring string variables in a regression

    I have panel data with a string variable for state and a numeric variable for year. I'd like to run a regression consisting of my outcome (v) and each year and state in the data set.

    I've tried
    regress v i.year i.state

    but it doesn't work since stata can't factor a string variable. I then tried using tab state, generate(state) but that left me with a series of dummy variables of state1, state2, state3, state4, etc. rather than having each dummy variable labeled with the state name. Is there a way I can accomplish something equivalent to i. in the context of a regression for a string variable so I can get something similar to the output I achieve with i.year?

  • #2
    Welcome to the Stata Forum/Statalist

    Code:
    help encode
    Last edited by Marcos Almeida; 02 May 2020, 17:00.
    Best regards,

    Marcos

    Comment


    • #3
      I would suggest Marcos's approach for encoding string variables first. If it is too cumbersome, try the following:
      Code:
      xi: regress v i.year i.state

      Comment

      Working...
      X