BookmarkSubscribeRSS Feed
joon1
Quartz | Level 8

Dear Madam/Sir,

I would like to pick control firms (gvkey2 in dataset2 with respect to gvkey1 and year) using treatment firms (gvkey and merge_year in the same industry_code in dataset 1).

Have

dataset 1                                                        dataset 2

gvkey  merge_year industry_code                 gvkey1 year gvkey2

 

Want

new dataset (matching identifier: gvkey(dataset1)=gvkey1(dataset2), merge_year(dataset2)=year(dataset2))

gvkey  merge_year industry_code gvkey2

 

Any programming idea will be highly appreciated. Two datasets are attached.

 

Sincerely,

Joon

 

 

 

 

2 REPLIES 2
mkeintz
Jade | Level 19

@joon1 wrote:

 

I would like to pick control firms (gvkey2 in dataset2 with respect to gvkey1 and year) using treatment firms (gvkey and merge_year in the same industry_code in dataset 1).

Have

dataset 1                                                        dataset 2

gvkey  merge_year industry_code                 gvkey1 year gvkey2

 

Want

new dataset (matching identifier: gvkey(dataset1)=gvkey1(dataset2), merge_year(dataset2)=year(dataset2))

gvkey  merge_year industry_code gvkey2

 

Any programming idea will be highly appreciated. Two datasets are attached.

I don't understand your task well enough to consider this a program question yet.  My questions are:

  1. Your dataset2 apparently does not have an industry code variable, a variable that you want for matching.  Does that mean all pairs of gvkey1/gvkey2 in dataset2 represent companies already known to have the same industry code for the designated year?  Or do you need to search dataset1 to confirm whether two distinct GVKEY's have the same industry code in the same year?
  2. Assuming the industry code match mystery is resolved.
    1. What if, for a given gvkey1 in dataset1, there are no records in dataset2 with year=merge_year from dataset1?
    2. More generally what if there are N gvkey's in dataset1 all sharing the same merge_year and industry code but there are fewer than N matches available in dataset2?
    3. On the other hand, what if there are more than N dataset2 records that can match a set of N records in dataset1 with a given merge_year?  (this answer is probably self-evident, but please humor me).
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
joon1
Quartz | Level 8

Thank you for insightful comments, mkeintz.

You are correct. To simplify programming, I have dropped observations that have different industry (SIC code) between gvkey1 and gvkey 2 in dataset 2 to have only observations with the same industry between gvkey1 and gvkey2. The industry issue is resolved. I attach a part of revised dataset2 (it is over 8 million observations). For your a second serious questions, my goal is to have unique control firms (gvkey2) in a particular year that match between gvkey/merge_year in dataset1 and gvkey1/year in dataset 2. It could be multiple control firms (gvkey2) matched with gvkey in dataset 1 in a particular year.

Any programming advice will be highly appreciated.

Thanks

Joon1

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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