David Dai
David Dai

Reputation: 1

Stata/R Combining/Collapsing Observations with the Same ID

For observations with same ID, does Period_Begin of one observation equal to Period_End of another observation? If yes, aggregate revenue of the observations to make into one period. Mark period as complete, the revenue is of a complete year. SEE ATTACHED IMAGE. Goal

tried tagging dups. Stuck with how to make stata detect whether variable A of observation 1 equals to variable B of observation 2. Goal

Upvotes: -2

Views: 62

Answers (1)

Kathryn Roman Banda
Kathryn Roman Banda

Reputation: 39

I think that your goal would be a lot simpler if you start by either (1) converting your variables with dates into a date-time format that Stata actually recognizes:

https://www.stata.com/manuals/ddatetime.pdf

or (2) converting the dates into strings and splitting each date into 2 or 3 separate variables. For instance, 12/31/2019 would be separated into month 12, day 31, year 2019. For instructions, go here:

https://www.stata.com/manuals/dsplit.pdf

Once you have the dates parsed into separate variables, you can create indicators for dates that match, or you can sum revenue across variables. This should get you closer to being able to identify the time periods that overlap.

Upvotes: 1

Related Questions