Announcement

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

  • Generating a Dummy Variable for Pre Period Using Multiple Firm-Year Observations

    Hello,

    Please I need help creating a dummy variable Breached_Pre that is =1 in any of the prior 3 years to the Year when the Breached_firm==1. I have multiple firm-year observations, so the normal _n-1, _n-2 and _n-3 does not work.
    For example, if Breached_firm==1 for Apple Co. in 2020, I want the Breached_Pre to be =1 in 2019, 2018 and 2017.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float Year str551 Company float Breached_firm
    2007 "024 Pharma, Inc."                     0
    2008 "024 Pharma, Inc."                     0
    2009 "024 Pharma, Inc."                     0
    2010 "024 Pharma, Inc."                     0
    2011 "024 Pharma, Inc."                     0
    2018 "10x Genomics, Inc."                   0
    2018 "10x Genomics, Inc."                   0
    2018 "10x Genomics, Inc."                   0
    2019 "10x Genomics, Inc."                   0
    2019 "10x Genomics, Inc."                   0
    2020 "10x Genomics, Inc."                   0
    2020 "10x Genomics, Inc."                   0
    2021 "10x Genomics, Inc."                   0
    2021 "10x Genomics, Inc."                   0
    2022 "10x Genomics, Inc."                   0
    2022 "10x Genomics, Inc."                   0
    2023 "10x Genomics, Inc."                   0
    2023 "10x Genomics, Inc."                   0
    2020 "1606 CORP."                           0
    2020 "1606 CORP."                           0
    2021 "1606 CORP."                           0
    2022 "1606 CORP."                           0
    2022 "1606 CORP."                           0
    2023 "1606 CORP."                           0
    2023 "1606 CORP."                           0
    2007 "180 DEGREE CAPITAL CORP. /NY/"        0
    2008 "180 DEGREE CAPITAL CORP. /NY/"        0
    2009 "180 DEGREE CAPITAL CORP. /NY/"        0
    2010 "180 DEGREE CAPITAL CORP. /NY/"        0
    2011 "180 DEGREE CAPITAL CORP. /NY/"        0
    2012 "180 DEGREE CAPITAL CORP. /NY/"        0
    2013 "180 DEGREE CAPITAL CORP. /NY/"        0
    2014 "180 DEGREE CAPITAL CORP. /NY/"        0
    2014 "180 DEGREE CAPITAL CORP. /NY/"        0
    2015 "180 DEGREE CAPITAL CORP. /NY/"        0
    2016 "180 DEGREE CAPITAL CORP. /NY/"        0
    2016 "180 DEGREE CAPITAL CORP. /NY/"        0
    2017 "180 DEGREE CAPITAL CORP. /NY/"        0
    2018 "180 DEGREE CAPITAL CORP. /NY/"        0
    2019 "180 DEGREE CAPITAL CORP. /NY/"        0
    2020 "180 DEGREE CAPITAL CORP. /NY/"        0
    2021 "180 DEGREE CAPITAL CORP. /NY/"        0
    2022 "180 DEGREE CAPITAL CORP. /NY/"        0
    2023 "180 DEGREE CAPITAL CORP. /NY/"        0
    2016 "180 Life Sciences Corp."              0
    2016 "180 Life Sciences Corp."              0
    2016 "180 Life Sciences Corp."              0
    2016 "180 Life Sciences Corp."              0
    2017 "180 Life Sciences Corp."              0
    2017 "180 Life Sciences Corp."              0
    2018 "180 Life Sciences Corp."              0
    2018 "180 Life Sciences Corp."              0
    2019 "180 Life Sciences Corp."              0
    2019 "180 Life Sciences Corp."              0
    2020 "180 Life Sciences Corp."              0
    2020 "180 Life Sciences Corp."              0
    2021 "180 Life Sciences Corp."              0
    2021 "180 Life Sciences Corp."              0
    2022 "180 Life Sciences Corp."              0
    2022 "180 Life Sciences Corp."              0
    2023 "180 Life Sciences Corp."              0
    2013 "1847 Holdings LLC"                    0
    2013 "1847 Holdings LLC"                    0
    2014 "1847 Holdings LLC"                    0
    2015 "1847 Holdings LLC"                    0
    2016 "1847 Holdings LLC"                    0
    2016 "1847 Holdings LLC"                    0
    2017 "1847 Holdings LLC"                    0
    2018 "1847 Holdings LLC"                    0
    2018 "1847 Holdings LLC"                    0
    2019 "1847 Holdings LLC"                    0
    2019 "1847 Holdings LLC"                    0
    2020 "1847 Holdings LLC"                    0
    2020 "1847 Holdings LLC"                    0
    2020 "1847 Holdings LLC"                    0
    2021 "1847 Holdings LLC"                    0
    2021 "1847 Holdings LLC"                    0
    2021 "1847 Holdings LLC"                    0
    2022 "1847 Holdings LLC"                    0
    2022 "1847 Holdings LLC"                    0
    2023 "1847 Holdings LLC"                    0
    2023 "1847 Holdings LLC"                    0
    2018 "1895 Bancorp of Wisconsin, Inc."      0
    2018 "1895 Bancorp of Wisconsin, Inc."      0
    2019 "1895 Bancorp of Wisconsin, Inc."      0
    2019 "1895 Bancorp of Wisconsin, Inc."      0
    2020 "1895 Bancorp of Wisconsin, Inc."      0
    2020 "1895 Bancorp of Wisconsin, Inc. /MD/" 0
    2020 "1895 Bancorp of Wisconsin, Inc. /MD/" 0
    2020 "1895 Bancorp of Wisconsin, Inc. /MD/" 0
    2021 "1895 Bancorp of Wisconsin, Inc. /MD/" 0
    2021 "1895 Bancorp of Wisconsin, Inc. /MD/" 0
    2022 "1895 Bancorp of Wisconsin, Inc. /MD/" 0
    2022 "1895 Bancorp of Wisconsin, Inc. /MD/" 0
    2023 "1895 Bancorp of Wisconsin, Inc. /MD/" 0
    2023 "1895 Bancorp of Wisconsin, Inc. /MD/" 0
    2007 "1ST SOURCE CORP"                      0
    2008 "1ST SOURCE CORP"                      0
    2009 "1ST SOURCE CORP"                      0
    2010 "1ST SOURCE CORP"                      0
    end
    I look forward to your support!

  • #2
    Your data example does not contain any instance where the indicator "Breached_firm" is equal to 1. Therefore, the question becomes ambiguous. Does this indicator switch on and off? That is, once it becomes 1, can it switch back to 0?

    Secondly, for the desired indicator, should it correspond to the three years prior to the first instance where Breached_firm = 1, or to all instances where Breached_firm = 1? Assuming the latter, and modifying your data example:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float Year str551 Company float Breached_firm
    2007 "024 Pharma, Inc."                     0
    2008 "024 Pharma, Inc."                     0
    2009 "024 Pharma, Inc."                     0
    2010 "024 Pharma, Inc."                     0
    2011 "024 Pharma, Inc."                     1
    2018 "10x Genomics, Inc."                   0
    2018 "10x Genomics, Inc."                   0
    2018 "10x Genomics, Inc."                   0
    2019 "10x Genomics, Inc."                   0
    2019 "10x Genomics, Inc."                   0
    2020 "10x Genomics, Inc."                   1
    2020 "10x Genomics, Inc."                   1
    2021 "10x Genomics, Inc."                   0
    2021 "10x Genomics, Inc."                   0
    2022 "10x Genomics, Inc."                   0
    2022 "10x Genomics, Inc."                   0
    2023 "10x Genomics, Inc."                   0
    2023 "10x Genomics, Inc."                   0
    2020 "1606 CORP."                           0
    2020 "1606 CORP."                           0
    2021 "1606 CORP."                           0
    2022 "1606 CORP."                           0
    2022 "1606 CORP."                           0
    2023 "1606 CORP."                           0
    2023 "1606 CORP."                           0
    2007 "180 DEGREE CAPITAL CORP. /NY/"        0
    2008 "180 DEGREE CAPITAL CORP. /NY/"        0
    2009 "180 DEGREE CAPITAL CORP. /NY/"        0
    2010 "180 DEGREE CAPITAL CORP. /NY/"        0
    2011 "180 DEGREE CAPITAL CORP. /NY/"        0
    2012 "180 DEGREE CAPITAL CORP. /NY/"        0
    2013 "180 DEGREE CAPITAL CORP. /NY/"        0
    2014 "180 DEGREE CAPITAL CORP. /NY/"        0
    2014 "180 DEGREE CAPITAL CORP. /NY/"        0
    2015 "180 DEGREE CAPITAL CORP. /NY/"        0
    2016 "180 DEGREE CAPITAL CORP. /NY/"        0
    2016 "180 DEGREE CAPITAL CORP. /NY/"        0
    2017 "180 DEGREE CAPITAL CORP. /NY/"        0
    2018 "180 DEGREE CAPITAL CORP. /NY/"        0
    2019 "180 DEGREE CAPITAL CORP. /NY/"        0
    2020 "180 DEGREE CAPITAL CORP. /NY/"        0
    2021 "180 DEGREE CAPITAL CORP. /NY/"        1
    2022 "180 DEGREE CAPITAL CORP. /NY/"        0
    2023 "180 DEGREE CAPITAL CORP. /NY/"        1
    2016 "180 Life Sciences Corp."              0
    2016 "180 Life Sciences Corp."              0
    2016 "180 Life Sciences Corp."              0
    2016 "180 Life Sciences Corp."              0
    2017 "180 Life Sciences Corp."              0
    2017 "180 Life Sciences Corp."              0
    2018 "180 Life Sciences Corp."              0
    2018 "180 Life Sciences Corp."              0
    2019 "180 Life Sciences Corp."              0
    2019 "180 Life Sciences Corp."              0
    2020 "180 Life Sciences Corp."              0
    2020 "180 Life Sciences Corp."              0
    2021 "180 Life Sciences Corp."              0
    2021 "180 Life Sciences Corp."              0
    2022 "180 Life Sciences Corp."              0
    2022 "180 Life Sciences Corp."              0
    2023 "180 Life Sciences Corp."              0
    2013 "1847 Holdings LLC"                    0
    2013 "1847 Holdings LLC"                    0
    2014 "1847 Holdings LLC"                    0
    2015 "1847 Holdings LLC"                    0
    2016 "1847 Holdings LLC"                    0
    2016 "1847 Holdings LLC"                    0
    2017 "1847 Holdings LLC"                    0
    2018 "1847 Holdings LLC"                    0
    2018 "1847 Holdings LLC"                    0
    2019 "1847 Holdings LLC"                    0
    2019 "1847 Holdings LLC"                    0
    2020 "1847 Holdings LLC"                    0
    2020 "1847 Holdings LLC"                    0
    2020 "1847 Holdings LLC"                    0
    2021 "1847 Holdings LLC"                    0
    2021 "1847 Holdings LLC"                    0
    2021 "1847 Holdings LLC"                    0
    2022 "1847 Holdings LLC"                    0
    2022 "1847 Holdings LLC"                    0
    2023 "1847 Holdings LLC"                    0
    2023 "1847 Holdings LLC"                    0
    2018 "1895 Bancorp of Wisconsin, Inc."      0
    2018 "1895 Bancorp of Wisconsin, Inc."      0
    2019 "1895 Bancorp of Wisconsin, Inc."      1
    2019 "1895 Bancorp of Wisconsin, Inc."      1
    2020 "1895 Bancorp of Wisconsin, Inc."      0
    2020 "1895 Bancorp of Wisconsin, Inc. /MD/" 0
    2020 "1895 Bancorp of Wisconsin, Inc. /MD/" 0
    2020 "1895 Bancorp of Wisconsin, Inc. /MD/" 0
    2021 "1895 Bancorp of Wisconsin, Inc. /MD/" 0
    2021 "1895 Bancorp of Wisconsin, Inc. /MD/" 0
    2022 "1895 Bancorp of Wisconsin, Inc. /MD/" 0
    2022 "1895 Bancorp of Wisconsin, Inc. /MD/" 0
    2023 "1895 Bancorp of Wisconsin, Inc. /MD/" 1
    2023 "1895 Bancorp of Wisconsin, Inc. /MD/" 1
    2007 "1ST SOURCE CORP"                      0
    2008 "1ST SOURCE CORP"                      0
    2009 "1ST SOURCE CORP"                      0
    2010 "1ST SOURCE CORP"                      0
    end
    
    cap frame drop panel
    frame put * if Breached_firm, into(panel)
    frame panel{
        collapse Breached_firm, by(Company Year)
        expand 3
        bys Company Year: gen seq= Year-_n
        contract Company seq  Breached_firm
    }
    frlink m:1 Company Year, frame(panel Company seq)
    frget wanted=Breached_firm, from(panel)
    replace wanted=0 if missing(wanted)
    drop panel
    frame drop panel
    Res.:

    Code:
    . l, sepby(Co)
    
         +-----------------------------------------------------------------+
         | Year                                Company   Breach~m   wanted |
         |-----------------------------------------------------------------|
      1. | 2007                       024 Pharma, Inc.          0        0 |
      2. | 2008                       024 Pharma, Inc.          0        1 |
      3. | 2009                       024 Pharma, Inc.          0        1 |
      4. | 2010                       024 Pharma, Inc.          0        1 |
      5. | 2011                       024 Pharma, Inc.          1        0 |
         |-----------------------------------------------------------------|
      6. | 2018                     10x Genomics, Inc.          0        1 |
      7. | 2018                     10x Genomics, Inc.          0        1 |
      8. | 2018                     10x Genomics, Inc.          0        1 |
      9. | 2019                     10x Genomics, Inc.          0        1 |
     10. | 2019                     10x Genomics, Inc.          0        1 |
     11. | 2020                     10x Genomics, Inc.          1        0 |
     12. | 2020                     10x Genomics, Inc.          1        0 |
     13. | 2021                     10x Genomics, Inc.          0        0 |
     14. | 2021                     10x Genomics, Inc.          0        0 |
     15. | 2022                     10x Genomics, Inc.          0        0 |
     16. | 2022                     10x Genomics, Inc.          0        0 |
     17. | 2023                     10x Genomics, Inc.          0        0 |
     18. | 2023                     10x Genomics, Inc.          0        0 |
         |-----------------------------------------------------------------|
     19. | 2020                             1606 CORP.          0        0 |
     20. | 2020                             1606 CORP.          0        0 |
     21. | 2021                             1606 CORP.          0        0 |
     22. | 2022                             1606 CORP.          0        0 |
     23. | 2022                             1606 CORP.          0        0 |
     24. | 2023                             1606 CORP.          0        0 |
     25. | 2023                             1606 CORP.          0        0 |
         |-----------------------------------------------------------------|
     26. | 2007          180 DEGREE CAPITAL CORP. /NY/          0        0 |
     27. | 2008          180 DEGREE CAPITAL CORP. /NY/          0        0 |
     28. | 2009          180 DEGREE CAPITAL CORP. /NY/          0        0 |
     29. | 2010          180 DEGREE CAPITAL CORP. /NY/          0        0 |
     30. | 2011          180 DEGREE CAPITAL CORP. /NY/          0        0 |
     31. | 2012          180 DEGREE CAPITAL CORP. /NY/          0        0 |
     32. | 2013          180 DEGREE CAPITAL CORP. /NY/          0        0 |
     33. | 2014          180 DEGREE CAPITAL CORP. /NY/          0        0 |
     34. | 2014          180 DEGREE CAPITAL CORP. /NY/          0        0 |
     35. | 2015          180 DEGREE CAPITAL CORP. /NY/          0        0 |
     36. | 2016          180 DEGREE CAPITAL CORP. /NY/          0        0 |
     37. | 2016          180 DEGREE CAPITAL CORP. /NY/          0        0 |
     38. | 2017          180 DEGREE CAPITAL CORP. /NY/          0        0 |
     39. | 2018          180 DEGREE CAPITAL CORP. /NY/          0        1 |
     40. | 2019          180 DEGREE CAPITAL CORP. /NY/          0        1 |
     41. | 2020          180 DEGREE CAPITAL CORP. /NY/          0        1 |
     42. | 2021          180 DEGREE CAPITAL CORP. /NY/          1        1 |
     43. | 2022          180 DEGREE CAPITAL CORP. /NY/          0        1 |
     44. | 2023          180 DEGREE CAPITAL CORP. /NY/          1        0 |
         |-----------------------------------------------------------------|
     45. | 2016                180 Life Sciences Corp.          0        0 |
     46. | 2016                180 Life Sciences Corp.          0        0 |
     47. | 2016                180 Life Sciences Corp.          0        0 |
     48. | 2016                180 Life Sciences Corp.          0        0 |
     49. | 2017                180 Life Sciences Corp.          0        0 |
     50. | 2017                180 Life Sciences Corp.          0        0 |
     51. | 2018                180 Life Sciences Corp.          0        0 |
     52. | 2018                180 Life Sciences Corp.          0        0 |
     53. | 2019                180 Life Sciences Corp.          0        0 |
     54. | 2019                180 Life Sciences Corp.          0        0 |
     55. | 2020                180 Life Sciences Corp.          0        0 |
     56. | 2020                180 Life Sciences Corp.          0        0 |
     57. | 2021                180 Life Sciences Corp.          0        0 |
     58. | 2021                180 Life Sciences Corp.          0        0 |
     59. | 2022                180 Life Sciences Corp.          0        0 |
     60. | 2022                180 Life Sciences Corp.          0        0 |
     61. | 2023                180 Life Sciences Corp.          0        0 |
         |-----------------------------------------------------------------|
     62. | 2013                      1847 Holdings LLC          0        0 |
     63. | 2013                      1847 Holdings LLC          0        0 |
     64. | 2014                      1847 Holdings LLC          0        0 |
     65. | 2015                      1847 Holdings LLC          0        0 |
     66. | 2016                      1847 Holdings LLC          0        0 |
     67. | 2016                      1847 Holdings LLC          0        0 |
     68. | 2017                      1847 Holdings LLC          0        0 |
     69. | 2018                      1847 Holdings LLC          0        0 |
     70. | 2018                      1847 Holdings LLC          0        0 |
     71. | 2019                      1847 Holdings LLC          0        0 |
     72. | 2019                      1847 Holdings LLC          0        0 |
     73. | 2020                      1847 Holdings LLC          0        0 |
     74. | 2020                      1847 Holdings LLC          0        0 |
     75. | 2020                      1847 Holdings LLC          0        0 |
     76. | 2021                      1847 Holdings LLC          0        0 |
     77. | 2021                      1847 Holdings LLC          0        0 |
     78. | 2021                      1847 Holdings LLC          0        0 |
     79. | 2022                      1847 Holdings LLC          0        0 |
     80. | 2022                      1847 Holdings LLC          0        0 |
     81. | 2023                      1847 Holdings LLC          0        0 |
     82. | 2023                      1847 Holdings LLC          0        0 |
         |-----------------------------------------------------------------|
     83. | 2018        1895 Bancorp of Wisconsin, Inc.          0        1 |
     84. | 2018        1895 Bancorp of Wisconsin, Inc.          0        1 |
     85. | 2019        1895 Bancorp of Wisconsin, Inc.          1        0 |
     86. | 2019        1895 Bancorp of Wisconsin, Inc.          1        0 |
     87. | 2020        1895 Bancorp of Wisconsin, Inc.          0        0 |
         |-----------------------------------------------------------------|
     88. | 2020   1895 Bancorp of Wisconsin, Inc. /MD/          0        1 |
     89. | 2020   1895 Bancorp of Wisconsin, Inc. /MD/          0        1 |
     90. | 2020   1895 Bancorp of Wisconsin, Inc. /MD/          0        1 |
     91. | 2021   1895 Bancorp of Wisconsin, Inc. /MD/          0        1 |
     92. | 2021   1895 Bancorp of Wisconsin, Inc. /MD/          0        1 |
     93. | 2022   1895 Bancorp of Wisconsin, Inc. /MD/          0        1 |
     94. | 2022   1895 Bancorp of Wisconsin, Inc. /MD/          0        1 |
     95. | 2023   1895 Bancorp of Wisconsin, Inc. /MD/          1        0 |
     96. | 2023   1895 Bancorp of Wisconsin, Inc. /MD/          1        0 |
         |-----------------------------------------------------------------|
     97. | 2007                        1ST SOURCE CORP          0        0 |
     98. | 2008                        1ST SOURCE CORP          0        0 |
     99. | 2009                        1ST SOURCE CORP          0        0 |
    100. | 2010                        1ST SOURCE CORP          0        0 |
         +-----------------------------------------------------------------+
    
    .

    Comment


    • #3
      Hello and thank you for your response!

      By coincidence all the observations that showed when I used dataex turned out to have Breached_firm=0, but yes in my dataset I have Breached_firm=1 for some firm year observations. Yes, it can switch back to zero because this represents whether a company experienced a breach, which is the case in some years but not in others. So a firm can be breached in 2010 and 2015 for example, but not in all the other years.

      The variable Breached_Pre should be =1 for all the prior 3 years of the breached firm and I have multiple firm-year observations. For example, if firm X experienced a breach in year 2020, the Breached_firm=1 in 2020, and I want the Breached_Pre of firm X in 2019, 2018, and 2017 to be equal to 1. So exactly as the example you provided.
      I am using Stata16.

      I used the suggested command and I got the error that "if not allowed" for the second row of code, and "frame panel not found" for the third row.

      Could you please advise?

      Your support is much appreciated!

      Comment


      • #4
        The code in #2 should run fine in Stata 16. Have you tested the code as is? Otherwise, provide a dataex example that reproduces your error (data and commands).

        Comment


        • #5
          Yes, I have copied the code as is and run it as one command and also I tried running each code line separately. Both options gave errors.
          Running it as one command altogether generated the below:


          cap frame drop panel

          frame put * if Breached_firm, into(panel)
          if not allowed
          r(101);



          frame panel{
          frame panel not found
          r(111);


          collapse Breached_firm, by(Company Year)

          expand 3
          (137,480 observations created)


          bys Company Year: gen seq= Year-_n


          contract Company seq Breached_firm


          }
          } is not a valid command name
          r(199);



          frlink m:1 Company Year, frame(panel Company seq)
          variable Year not found
          r(111);



          frget wanted=Breached_firm, from(panel)
          variable panel not found
          (error in option from())
          r(111);



          replace wanted=0 if missing(wanted)
          variable wanted not found
          r(111);



          drop panel
          variable panel not found
          r(111);



          frame drop panel
          frame panel not found
          r(111);



          .
          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input str551 Company float(Breached_firm seq) byte _freq
          "024 Pharma, Inc."                     0 2004 1
          "024 Pharma, Inc."                     0 2005 2
          "024 Pharma, Inc."                     0 2006 3
          "024 Pharma, Inc."                     0 2007 3
          "024 Pharma, Inc."                     0 2008 3
          "024 Pharma, Inc."                     0 2009 2
          "024 Pharma, Inc."                     0 2010 1
          "10x Genomics, Inc."                   0 2015 1
          "10x Genomics, Inc."                   0 2016 2
          "10x Genomics, Inc."                   0 2017 3
          "10x Genomics, Inc."                   0 2018 3
          "10x Genomics, Inc."                   0 2019 3
          "10x Genomics, Inc."                   0 2020 3
          "10x Genomics, Inc."                   0 2021 2
          "10x Genomics, Inc."                   0 2022 1
          "1606 CORP."                           0 2017 1
          "1606 CORP."                           0 2018 2
          "1606 CORP."                           0 2019 3
          "1606 CORP."                           0 2020 3
          "1606 CORP."                           0 2021 2
          "1606 CORP."                           0 2022 1
          "180 DEGREE CAPITAL CORP. /NY/"        0 2004 1
          "180 DEGREE CAPITAL CORP. /NY/"        0 2005 2
          "180 DEGREE CAPITAL CORP. /NY/"        0 2006 3
          "180 DEGREE CAPITAL CORP. /NY/"        0 2007 3
          "180 DEGREE CAPITAL CORP. /NY/"        0 2008 3
          "180 DEGREE CAPITAL CORP. /NY/"        0 2009 3
          "180 DEGREE CAPITAL CORP. /NY/"        0 2010 3
          "180 DEGREE CAPITAL CORP. /NY/"        0 2011 3
          "180 DEGREE CAPITAL CORP. /NY/"        0 2012 3
          "180 DEGREE CAPITAL CORP. /NY/"        0 2013 3
          "180 DEGREE CAPITAL CORP. /NY/"        0 2014 3
          "180 DEGREE CAPITAL CORP. /NY/"        0 2015 3
          "180 DEGREE CAPITAL CORP. /NY/"        0 2016 3
          "180 DEGREE CAPITAL CORP. /NY/"        0 2017 3
          "180 DEGREE CAPITAL CORP. /NY/"        0 2018 3
          "180 DEGREE CAPITAL CORP. /NY/"        0 2019 3
          "180 DEGREE CAPITAL CORP. /NY/"        0 2020 3
          "180 DEGREE CAPITAL CORP. /NY/"        0 2021 2
          "180 DEGREE CAPITAL CORP. /NY/"        0 2022 1
          "180 Life Sciences Corp."              0 2013 1
          "180 Life Sciences Corp."              0 2014 2
          "180 Life Sciences Corp."              0 2015 3
          "180 Life Sciences Corp."              0 2016 3
          "180 Life Sciences Corp."              0 2017 3
          "180 Life Sciences Corp."              0 2018 3
          "180 Life Sciences Corp."              0 2019 3
          "180 Life Sciences Corp."              0 2020 3
          "180 Life Sciences Corp."              0 2021 2
          "180 Life Sciences Corp."              0 2022 1
          "1847 Holdings LLC"                    0 2010 1
          "1847 Holdings LLC"                    0 2011 2
          "1847 Holdings LLC"                    0 2012 3
          "1847 Holdings LLC"                    0 2013 3
          "1847 Holdings LLC"                    0 2014 3
          "1847 Holdings LLC"                    0 2015 3
          "1847 Holdings LLC"                    0 2016 3
          "1847 Holdings LLC"                    0 2017 3
          "1847 Holdings LLC"                    0 2018 3
          "1847 Holdings LLC"                    0 2019 3
          "1847 Holdings LLC"                    0 2020 3
          "1847 Holdings LLC"                    0 2021 2
          "1847 Holdings LLC"                    0 2022 1
          "1895 Bancorp of Wisconsin, Inc."      0 2015 1
          "1895 Bancorp of Wisconsin, Inc."      0 2016 2
          "1895 Bancorp of Wisconsin, Inc."      0 2017 3
          "1895 Bancorp of Wisconsin, Inc."      0 2018 2
          "1895 Bancorp of Wisconsin, Inc."      0 2019 1
          "1895 Bancorp of Wisconsin, Inc. /MD/" 0 2017 1
          "1895 Bancorp of Wisconsin, Inc. /MD/" 0 2018 2
          "1895 Bancorp of Wisconsin, Inc. /MD/" 0 2019 3
          "1895 Bancorp of Wisconsin, Inc. /MD/" 0 2020 3
          "1895 Bancorp of Wisconsin, Inc. /MD/" 0 2021 2
          "1895 Bancorp of Wisconsin, Inc. /MD/" 0 2022 1
          "1ST SOURCE CORP"                      0 2004 1
          "1ST SOURCE CORP"                      0 2005 2
          "1ST SOURCE CORP"                      0 2006 3
          "1ST SOURCE CORP"                      0 2007 3
          "1ST SOURCE CORP"                      0 2008 3
          "1ST SOURCE CORP"                      0 2009 3
          "1ST SOURCE CORP"                      0 2010 3
          "1ST SOURCE CORP"                      0 2011 3
          "1ST SOURCE CORP"                      0 2012 3
          "1ST SOURCE CORP"                      0 2013 3
          "1ST SOURCE CORP"                      0 2014 3
          "1ST SOURCE CORP"                      0 2015 3
          "1ST SOURCE CORP"                      0 2016 3
          "1ST SOURCE CORP"                      0 2017 3
          "1ST SOURCE CORP"                      0 2018 3
          "1ST SOURCE CORP"                      0 2019 3
          "1ST SOURCE CORP"                      0 2020 3
          "1ST SOURCE CORP"                      0 2021 2
          "1ST SOURCE CORP"                      0 2022 1
          "1stdibs.com, Inc."                    0 2016 1
          "1stdibs.com, Inc."                    0 2017 2
          "1stdibs.com, Inc."                    0 2018 3
          "1stdibs.com, Inc."                    0 2019 3
          "1stdibs.com, Inc."                    0 2020 3
          "1stdibs.com, Inc."                    0 2021 2
          "1stdibs.com, Inc."                    0 2022 1
          end

          Comment


          • #6
            Your data example in #5 appears to be a dataex of frame panel because you have the variable "seq" and the "_freq" variable from contract. So at some point, the code in #2 was executed. The error

            frame put * if Breached_firm, into(panel)
            if not allowed
            r(101);
            might arise if you copied the code from some editor that added invisible characters in front of the -if- qualifier. Here is what I suggest:

            Start with the commands

            Code:
            frame change default
            cap frame drop panel
            then load your dataset

            Code:
            use mydataset, clear
            where you change "mydataset" to the name of your dataset.


            Finally, you can retype the commands

            Code:
            frame put * if Breached_firm, into(panel)
            frame panel{
                collapse Breached_firm, by(Company Year)
                expand 3
                bys Company Year: gen seq= Year-_n
                contract Company seq  Breached_firm
            }
            frlink m:1 Company Year, frame(panel Company seq)
            frget wanted=Breached_firm, from(panel)
            replace wanted=0 if missing(wanted)
            drop panel
            frame drop panel
            instead of copying and pasting in case the error persists. Otherwise my question remains: what happens if you copy, paste and run the code in #2. Do you get any result?

            Comment

            Working...
            X