Announcement

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

  • Seasonal Dummy - Panel Data

    I am looking to create dummy variables for each quarter (e.g. Q1, Q2, Q3, Q4). I have a panel data set with 35 firms.

    Date Variable: quarter1

    Any help would be greatly appreciated.

    Thanks
    Attached Files

  • #2
    Well, there are at least two ways to do this:

    Code:
    // METHOD ONE
    tab quarter1, gen(q)
    
    // METHOD TWO
    levelsof quarter1, local(quarters)
    foreach q of local quarters {
        local qq: display %tq `q'
        gen d`qq' = `q'.quarter1
    }
    And there are others.

    But probably you shouldn't do this at all. Why do you need these variables? The commonest answer is to use them as variables in a regression equation. If that's what you want them for, don't waste your time doing this. Use factor-variable notation instead. See -help fvvarlist- for details, but the gist of it is:

    Code:
    regression_command outcome other_predictor_variables i.quarter1
    Stata will automatically expand i.quarter1 into a list of "virtual" indicator ("dummy") variables for quarter1 in your regression. It won't actually create any variables in your data set, but since usually these variables serve no other purpose, they would just be a waste of space anyway.

    All of this assumes that your variable quarter1 is, in fact, a Stata internal format quarterly date variable, with display format %tq, and not a string variable. If it is a string, you need to convert it with the -quarterly()- functioin.

    That said, you shouldn't make people guess about your data. Please read the Forum FAQ, with special emphasis on #12 to learn about the helpful ways to show data, code, or Stata results. There you will learn that screenshots are the least useful approach. In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 15.1 or a fully updated version 14.2, it is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      Hello Clyde,

      Thanks for the response. Yes, you are correct in your assumption that I wanted to use this date dummy variable in a regression. Now that you showed me the method to use the factor-variable notation this seems like a better way.

      My apologies on the screenshot. I will use the dataex command in the future.

      Again, thank you.

      Comment

      Working...
      X