Announcement

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

  • Year dummy order

    Hi everyone

    I have an issue with a variable I have generated to control for the economic crisis
    What I did was as follows:

    Code:
    generate crisis = year > 2007
    This is to control for the financial crisis that started from 2008 onwards and then I tried to see if this variable is significant to tell something about the data.

    Now the problem is that I found out that the order of the variable does not hold, i.e. when sorting the data according to the ID number the crisis variable values (0 and 1) does not correspond or match the correct year. For example I sometimes finds them as 1 against the year 2006 whereas it should be against 2008-2011.

    Does anyone have a clue?


  • #2
    If, for some reason, year is ever missing, I would code it

    Code:
    gen crisis = year > 78 & !missing(year)
    But, I don't understand why what you describe would happen. Maybe show your actual code and output, including

    Code:
    tab2 year crisis
    and it will make some sense.
    -------------------------------------------
    Richard Williams
    Professor Emeritus of Sociology
    University of Notre Dame
    StataNow Version: 19.5 MP (2 processor)

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

    Comment


    • #3
      Hi Richard

      Here are some details

      Code:
             |        crisis
            year |         0          1 |     Total
      -----------+----------------------+----------
            2005 |       197          0 |       197 
            2006 |       197          0 |       197 
            2007 |       197          0 |       197 
            2008 |         0        197 |       197 
            2009 |         0        197 |       197 
            2010 |         0        197 |       197 
            2011 |         0        197 |       197 
      -----------+----------------------+----------
           Total |       591        788 |     1,379
      I we discussed the interaction term earlier today, I double checked the data and found that the dummy CRISIS does not correspond to the correct years.

      The code to generate the variables is

      Code:
      generate crisis = year > 2007

      Comment


      • #4
        It is hard to reconcile
        For example I sometimes finds them as 1 against the year 2006 whereas it should be against 2008-2011.
        with
        Code:
               |        crisis
              year |         0          1 |     Total
        -----------+----------------------+----------
              2005 |       197          0 |       197
              2006 |       197          0 |       197
              2007 |       197          0 |       197
              2008 |         0        197 |       197
              2009 |         0        197 |       197
              2010 |         0        197 |       197
              2011 |         0        197 |       197
        -----------+----------------------+----------
             Total |       591        788 |     1,379
        The table clearly shows that crisis = 1 corresponds exactly to year being between 2008 and 2011. So show us where and how exactly you saw crisis == 1 with year == 2006 in the same observation: either give us the commands and output that revealed this, or show us a snapshot from the data browser.

        Comment


        • #5
          I don't see any errors in that table. 2005, 2006 and 2007 are all coded 0, 2008 on are coded 1. Am I missing something?
          -------------------------------------------
          Richard Williams
          Professor Emeritus of Sociology
          University of Notre Dame
          StataNow Version: 19.5 MP (2 processor)

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

          Comment


          • #6
            Hi Clyde

            This is how it appear in the data editor where the dummy should appear in this order according to the corresponding year (0 0 0 1 1 1 1 )

            Click image for larger version

Name:	crisis.png
Views:	1
Size:	983 Bytes
ID:	123825

            Comment


            • #7
              Does sorting the data like
              Code:
              sort id year
              may contribute to this?

              Comment


              • #8
                Do a listing of id, year, and crisis. Otherwise we can't tell if there is an error or not, I.e we need to see year and crisis on the same line.
                -------------------------------------------
                Richard Williams
                Professor Emeritus of Sociology
                University of Notre Dame
                StataNow Version: 19.5 MP (2 processor)

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

                Comment


                • #9
                  Hope this will do

                  Click image for larger version

Name:	crisis.png
Views:	1
Size:	8.1 KB
ID:	123949

                  Comment


                  • #10
                    This is very bizarre indeed. One possibility is that your Stata installation is corrupted. You might try running -update all- and then redoing this to see if it still happens. But if that doesn't solve the problem, then it is likely that there is something in your code that is changing the value of year or crisis after you generate crisis but before you get to the result you show in your most recent post.

                    I would look through my code to see if there are any commands that might be doing that. Look for any -replace-, -recode-, -mvencode- commands. Look also for -drop- and -gen-. And think about any -append- or -merge- commands. Also, if you did any -collapse-s, they might be culpable. Unfortunately the list of commands that can change a variable is almost endless. But if on re-reading your code you can't find anything, I would debug using the following procedure:

                    1. Identify the point in the code where crisis is created: generate crisis = year > 2007. Immediately after that statement insert a line: -assert crisis == (year > 2007)-.
                    2. Identify the point in the code where your data browser showed the results above. Insert the same -assert- statement after that line of code.
                    3. Rerun all the code: the first -assert- should pass and the second should fail. If the second doesn't fail, check your browse window again: I don't think it will look like what is posted and your problem will probably have been solved. If the second -assert- doesn't fail and your browser still shows these same results at this point, contact technical support. If the first -assert- doesn't pass, contact technical support.
                    4. Assuming the first- assert- passes and the second fails, liberally sprinkle copies of the -assert- statement every few lines or so in the code between the ones created in steps 1 and 2. Re-run all the code. The problem will lie somewhere between the last -assert- that passes and the first one that fails. If you have spaced the -asserts- close enough together that will be a small number of lines of code to scrutinize (or share with us on this forum if need be.)
                    Last edited by Clyde Schechter; 02 Aug 2014, 17:07. Reason: Correct typo.

                    Comment


                    • #11
                      Weird. In addition to everything Clyde suggests, is there any chance you have multiple crisis or year variables? Remember, in Stata case matters, so crisis, Crisis, and CRISIS are all different variables. I notice that in your output above you have had both crisis and CRISIS.
                      -------------------------------------------
                      Richard Williams
                      Professor Emeritus of Sociology
                      University of Notre Dame
                      StataNow Version: 19.5 MP (2 processor)

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

                      Comment


                      • #12
                        Clyde, Thank you very much for the detailed reply.
                        I will see how I can get my head around this issue, otherwise recreating the variable and estimating all models all over again would be the last resort.

                        Regrads

                        Comment


                        • #13
                          Richard,

                          No, I am sure it is not multiple variable.
                          I should have done something to the variable and it could be when combining datasets.

                          Thank you very much Richard

                          Comment


                          • #14
                            If you are merging or appending different files, it is certainly possible that bad crisis codes could overwrite, or get added to, good crisis codes. I suggest that, once you finish combining files, you delete any existing crisis variable and regenerate it from scratch. If that doesn't solve the problem, then I will go to the Notre Dame Grotto and light a candle for you.
                            -------------------------------------------
                            Richard Williams
                            Professor Emeritus of Sociology
                            University of Notre Dame
                            StataNow Version: 19.5 MP (2 processor)

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

                            Comment


                            • #15
                              p.s. If this does solve the problem, don't forget to redo any earlier analysis that involved the faulty version of crisis.
                              -------------------------------------------
                              Richard Williams
                              Professor Emeritus of Sociology
                              University of Notre Dame
                              StataNow Version: 19.5 MP (2 processor)

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

                              Comment

                              Working...
                              X