Announcement

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

  • Numbering a variable based on previous observation

    Dear all

    I want to make a moderating variable called M&A active and give firms (identified by variable gvkey) a 0 in fyears (variable of fiscal year ) before acquisition or in every year between 1997-2015 if they never had an M&A. And a 1 in year from M&A and years AFTER FIRST M&A. Now, firms that never had an M&A already have a 0 in variable maactive but the firms that had an m&a only got a 1 in the years of the ma and not in the years after or in-between them. In the screenshot below you can see an example of ABBOT LABORATORIES.


    I tried the following code: by gvkey (fyear), sort: replace maactive = maactive [_n-1] if maactive = 1

    because I thought that it would give firms based on gvkey a 1 in the variable maactive if the previous observation of their gvkey is a 1. But I did not work out. I received error code r(101) weights not allowed. Could someone help me with this?



    Click image for larger version

Name:	Schermafbeelding 2021-05-18 om 11.39.20.png
Views:	2
Size:	776.0 KB
ID:	1610315

  • #2
    Code:
    by gvkey (fyear), sort: replace maactive = 1 if maactive [_n-1] == 1

    Comment


    • #3
      Thank you for responding Nick! I tried the code but I got the same error (r101 - weights not allowed). Do you know that the problem ?

      Comment


      • #4
        Sorry; I fixed one error and should have fixed another in #1. Remove the space

        by gvkey (fyear), sort: replace maactive = 1 if maactive[_n-1] == 1

        Comment


        • #5
          Works fine, thank you!

          Comment

          Working...
          X