Announcement

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

  • Creating dummy based on persistence of a variable

    Dear All
    I have a panel of firms (say, 2 firms, A&B) for 10 years(2001-2010). The variable of interest is the profits which I already generated. I would like to create a group (say 1) for those firm-years in which firms profits are, negative for 3 consecutive years. Thus if A reports negative cash flows during 2001,2002&2003, then I would like to have Group=1 during the year 2003 for the firm A. Based on Group 1, I would like to create 2 more sub-groups. Sub-Group A where firms register +ve profits in the following year after falling in Group1 &Sub-Group B where the firm register -ve profits again after falling in Group1(akin to 4 years of continuous negative profits). Continuing my example, if in 2004, if firm A reports +ve profits it will be in sub-group A & if firm A reports -ve profits in 2004, then A falls in Sub-Group B.
    How to create groups in the above scenario?
    Thanks in Advance

  • #2
    I got lost in the middle here. You say you have two firms and 10 years. So, with any criteria either those firms are the same or they are different. It's not clear to me that either way adding an indicator variable is much help to anything much downstream. With just 20 data points adding predictors to whatever you have already is the wrong way to go.

    it's not quite trivial to add that talk of firms A and B and subgroups A and B doesn't make your question clearer.

    Better far not to abstract but to show your real data, or a realistic analogue with the same variable names, or an example of either, with a worked example of what you want.

    Comment


    • #3
      I am extremely sorry for making a vague query. I will try to explain with the help of the following table.
      firm name year profits dummy
      a 2001 -300
      a 2002 -500
      a 2003 -600 1
      a 2004 12
      a 2005 150
      a 2006 1550
      a 2007 2000
      a 2008 -100
      a 2009 -200
      a 2010 600
      b 2001 0
      b 2002 -180
      b 2003 -2500
      b 2004 -3000 1
      b 2005 -4000 1
      b 2006 500
      b 2007 650
      b 2008 -300
      b 2009 -250
      b 2010 100
      In the above table dummy, 1 is given to firm "a" during the year 2003 based on the logic that it consecutively reported loss for 3 years. Similarly for the firm "b" during the year 2004, dummy 1 is given since it was its 3rd year of consecutive loss(2002,2003,2004). Again for the firm "b" dummy 1 was given during the year 2005 for its 3 years of consecutive losses(2003,2004,2005). Thus I would like to create dummy =1 ,wherever a firm reports 3 years of consecutive negative profits. How can I create such dummies was my first question
      Last edited by lal mohan kumar; 21 Nov 2019, 12:33.

      Comment


      • #4
        Thanks for the details. Here is one way to do it. Please note the use of dataex to give a data example (FAQ Advice #12):


        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input str1 firmname int(year profits) byte dummy
        "a"    2001  -300 .     
        "a" 2002  -500 .
        "a" 2003  -600 1
        "a" 2004    12 .
        "a" 2005   150 .
        "a" 2006  1550 .
        "a" 2007  2000 .
        "a" 2008  -100 .
        "a" 2009  -200 .
        "a" 2010   600 .
        "b" 2001     0 .
        "b" 2002  -180 .
        "b" 2003 -2500 .
        "b" 2004 -3000 1
        "b" 2005 -4000 1
        "b" 2006   500 .
        "b" 2007   650 .
        "b" 2008  -300 .
        "b" 2009  -250 .
        "b" 2010   100 .
        end
        
        encode firmname, gen(id)
        tsset id year 
        
        gen wanted = (profits < 0) & (L1.profits < 0) & (L2.profits < 0) 
        
        list, sepby(id) 
        
             +-------------------------------------------------+
             | firmname   year   profits   dummy   id   wanted |
             |-------------------------------------------------|
          1. |        a   2001      -300       .    a        0 |
          2. |        a   2002      -500       .    a        0 |
          3. |        a   2003      -600       1    a        1 |
          4. |        a   2004        12       .    a        0 |
          5. |        a   2005       150       .    a        0 |
          6. |        a   2006      1550       .    a        0 |
          7. |        a   2007      2000       .    a        0 |
          8. |        a   2008      -100       .    a        0 |
          9. |        a   2009      -200       .    a        0 |
         10. |        a   2010       600       .    a        0 |
             |-------------------------------------------------|
         11. |        b   2001         0       .    b        0 |
         12. |        b   2002      -180       .    b        0 |
         13. |        b   2003     -2500       .    b        0 |
         14. |        b   2004     -3000       1    b        1 |
         15. |        b   2005     -4000       1    b        1 |
         16. |        b   2006       500       .    b        0 |
         17. |        b   2007       650       .    b        0 |
         18. |        b   2008      -300       .    b        0 |
         19. |        b   2009      -250       .    b        0 |
         20. |        b   2010       100       .    b        0 |
             +-------------------------------------------------+

        Comment


        • #5
          Thank you Nick

          Comment

          Working...
          X