BookmarkSubscribeRSS Feed
EJAA
Obsidian | Level 7

Hi All

 

Thanks in advance for the help to solve my problem; 

 

My problem is outlined below;

 

From Column 2 in Table 1 shows firms that are linked to a specific firm. So for instance, firm with id 101 is linked to firm with id 102,104 and 103 while firm with id number 102 is linked with two firms thus 104 and 101.

Table 1: Interconnected firms

ID

Firmid1

Firmid2

Firmid3

Firmid4

101

102

104

103

 

102

104

101

 

 

103

101

103

104

 

104

104

1002

101

 

 

Table 2 indicates firm characteristics (size,roa)

date

ID

size

Roa

2010

101

6

12

2011

101

2

14

2012

101

5

13

2010

102

2

19

2011

102

4

14

2012

102

2

12

2010

103

3

13

2011

103

2

16

2012

103

1

19

2010

104

6

9

2011

104

7

8

2012

104

8

10

 

What I want to do is that, for the list of firms connected to a specific firm in table 1, I want to use propensity score matching to match firms that have similar characteristics and are connected using size and roa from table 2. So for instance from table 1, firm with id 101 is linked to 3 firms thus 102,104 and 103. Hence from the three firms linked to 101, I want to use propensity score matching to establish which of the three firms have similar features with 101 using size, roa.

 

Thanks for the help. 

 

 

3 REPLIES 3
Ksharp
Super User

The best choice is use SAS/OR to get this kind fo connection component.

After link all these ID up, it is easy to get what you want.

 

data x;
input ID Firmid1 Firmid2 Firmid3 Firmid4;
cards;
101 102 104 103 .
102 104 101 . .
103 101 103 104 .
104 104 1002 101 .
;
run;
data have;
 set x;
 array x{*} Firmid1-Firmid4;
 from=id;
 do i=1 to dim(x);
   if not missing(x{i}) then do;to=x{i};output;end;
 end;
 keep from to;
run;


data full;
  set have end=last;
  if _n_ eq 1 then do;
   declare hash h();
    h.definekey('node');
     h.definedata('node');
     h.definedone();
  end;
  output;
  node=from; h.replace();
  from=to; to=node;
  output;
  node=from; h.replace();
  if last then h.output(dataset:'node');
  drop node;
run;


data want(keep=node household);
declare hash ha(ordered:'a');
declare hiter hi('ha');
ha.definekey('count');
ha.definedata('last');
ha.definedone();
declare hash _ha(hashexp: 20);
_ha.definekey('key');
_ha.definedone();

if 0 then set full;
declare hash from_to(dataset:'full(where=(from is not missing and to is not missing))',hashexp:20,multidata:'y');
 from_to.definekey('from');
 from_to.definedata('to');
 from_to.definedone();

if 0 then set node;
declare hash no(dataset:'node');
declare hiter hi_no('no');
 no.definekey('node');
 no.definedata('node');
 no.definedone();
 

do while(hi_no.next()=0);
 household+1; output;
 count=1;
 key=node;_ha.add();
 last=node;ha.add();
 rc=hi.first();
 do while(rc=0);
   from=last;rx=from_to.find();
   do while(rx=0);
     key=to;ry=_ha.check();
      if ry ne 0 then do;
       node=to;output;rr=no.remove(key:node);
       key=to;_ha.add();
       count+1;
       last=to;ha.add();
      end;
      rx=from_to.find_next();
   end;
   rc=hi.next();
end;
ha.clear();_ha.clear();
end;
stop;
run;
EJAA
Obsidian | Level 7

Dear KSharp

Thanks very much for the great help. Sorry for late update to your reply on my problem.

I have followed the codes closely  but the final output which is dataset want contains only two columns thus node and household.

Please at what point do I use table 2 as expounded in my problem in your codes. Thanks very much.

 

 

Rick_SAS
SAS Super FREQ

Check out PROC PSMATCH in SAS/STAT, which performs propensity score matching.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 448 views
  • 1 like
  • 3 in conversation