Announcement

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

  • Adding rows for specific unique identifiers in a dataset conditional on some characteristics

    Dear Stata Community,

    I am relatively new to Stata (switched from R to Stata) and I am currently experiencing some difficulties in adding rows to my dataset. I did not find an easy solution to do it apart from adding rows at the end of a dataset which is not desired in my case.

    My dataset consists of more than 300'000 rows and I want to add rows for a specific "identifier" if there are insufficient observations/rows available. An example: A firm is delisted 12 months after the effective date of an M&A transaction and thus, only 12 rows are available in my dataset. In my analysis, however, I want to add rows for each firm with insufficient "rows" and fill in additional information until a period of at least 36 months is covered for each firm (i.e. I want to implement a similar approach as outlined by Mitchell and Stanfford (2000, p.298), Managerial Decisions and Long-Term Stock Price Performance).

    Is there an easy command in order to do this time efficiently?

    Thank you in advance and kind regards
    Andreas Mueller

  • #2
    You can add additional observations with (e.g.) the expand command.

    I don't have the book or paper you refer to, so I cannot advise on how to add the "additional information".

    Comment


    • #3
      Another possibility would be -fillin-. You would first need a variable to sequentially number the available observations within firm, if you don't have one. With that, -fillin- does what I think you want.

      Code:
      by firm: gen byte seqnum = _n
      summ seqnum // verify that seqnum has min = 1, max = 36
      fillin firm seqnum  //
      //
      sort firm seqnum // apparently order matters to you
      tabulate _fillin // document new observations added
      Regards, Mike

      Comment


      • #4
        Andreas,

        Operationally, how do you plan to "fill in additional information until a period of at least 36 months is covered for each firm" ?

        You might want to check -merge-. Depending on the case, a -merge- will add observations to your original (i.e. master) data set and bring in additional information. All in one step.
        See -help append-, also.
        You should:

        1. Read the FAQ carefully.

        2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

        3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

        4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

        Comment

        Working...
        X