nwcluster for the overall network

140 views
Skip to first unread message

Marziyeh Rostami

unread,
Jan 11, 2016, 2:05:09 PM1/11/16
to nwcommands
Hi all,

I have a data set of several co-invention networks each  for a firm-year.

For each network I need local and overall clustering,  and average shortest path.
I used nwcluster and nwgeodestic. it displays average clustering , overall clustering and avg shortest path. However I dont know how to store these results as stata variable for each network.
I would be grateful if someone help.
Best,
Marzieh

Thomas Grund

unread,
Jan 11, 2016, 3:10:16 PM1/11/16
to Marziyeh Rostami, nwcommands
Hi Marziyeh,

check out the return vector after executing the commands:

. return list

You will find that after executing the command "nwgeodesic" the return vector gets populated with different scalars. For example, you will see "r(avgpath)" which holds the average shortest path length for a particular network. You can refer to such a scalar afterwards and display it. 

. di r(avgpath)

Alternatively, you can use this information to populate a variable in your dataset. Here is a little example that does this for the florentine data where you have to networks.

// Load the example data
webnwuse florentine, nwclear

// This command also generates the scalar "r(names)" with the names of all negtworks. You could also use "nwunab" or other commands to get this.
nwset

// Generate a new variable where you want to store the average short path lengths for the networks
gen avgpath = .
local i = 1

// Loop through your networks and populate the i'th observation of variable avgpath with the average path of the i'th network in your list r(names) and increment i
foreach onenet in `r(names)' {
nwgeodesic `onenet', xvars 
        replace avgpath = `r(avgpath)' in `i'
local i = `i' + 1
}

Notice that this solution to populate the new variable requires that you have at least as many observations in your data as networks. But you can also write some code to check this and, if necessary, increase the number of observations.

nwset
if _N < `r(network)' {





--
You received this message because you are subscribed to the Google Groups "nwcommands" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwcommands+...@googlegroups.com.
Visit this group at https://groups.google.com/group/nwcommands.
To view this discussion on the web visit https://groups.google.com/d/msgid/nwcommands/44267636-9c3d-4d00-9208-dbc65991e41f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas Grund

unread,
Jan 11, 2016, 3:13:14 PM1/11/16
to Marziyeh Rostami, nwcommands
This is the code to increase the number of observations if necessary.

nwset

if `r(networks)' > _N {
set obs `r(networks)'
}

Hope this helps.

Best,
Thomas

On Mon, Jan 11, 2016 at 7:05 PM, Marziyeh Rostami <marziyeh...@gmail.com> wrote:

--
Reply all
Reply to author
Forward
0 new messages