BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aimsmith12
Calcite | Level 5

Good evening,

 

I'm working with a panel data set consisting of firm-year observations. This data set includes a dummy variable called "acquisition" that equals 1 if the firm made an acquisition during the current year and 0 otherwise. Now, I'd like to construct a new dummy variable that captures prior acquisition experience. More specifically, I'd like for this new variable to equal 1 if the acquisition dummy for this firm equals 1 in any prior year and 0 otherwise. Unfortunately, I'm having trouble figuring out the appropriate code. I thought it would be easiest to first create a count variable that reveals the number of prior years with merger activity and then construct a dummy variable equal to 1 any time the count variable carries a non-zero value. However, I can't seem to get the count variable to work. 

 

 

Does anyone have any advice?  For simplicity, you can just assume that the data set consists of 3 variables: id, year, and acquisition (a dummy variable).

 

Thank you!

 

Aimee      

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

One way (assuming your data set is sorted by FIRM YEAR):

 

data want;

set have;

by firm;

retain prior_acquisition;

if first.firm then prior_acquisition = 0;

output;

prior_acquisition = max(prior_acquisition, acquisition);

run;

View solution in original post

2 REPLIES 2
Astounding
PROC Star

One way (assuming your data set is sorted by FIRM YEAR):

 

data want;

set have;

by firm;

retain prior_acquisition;

if first.firm then prior_acquisition = 0;

output;

prior_acquisition = max(prior_acquisition, acquisition);

run;

aimsmith12
Calcite | Level 5
Thank you so much for your help! I really appreciate it. The code you suggested does exactly what I was trying to do.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 686 views
  • 0 likes
  • 2 in conversation