39
SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University [email protected] www.grund.co.uk (with contributions from Peter Hedström, Yvonne Aberg, Lorien Jasny)

SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University [email protected]

  • Upload
    lamcong

  • View
    219

  • Download
    1

Embed Size (px)

Citation preview

Page 1: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

SOCIAL NETWORK ANALYSIS USING STATA

5 Sept 2014, Aarhus

Nordic and Baltic Stata Group Meeting

Thomas Grund Linköping University

[email protected]

www.grund.co.uk

(with contributions from Peter Hedström, Yvonne Aberg, Lorien Jasny)

Page 2: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

http://nwcommands.org

Email list https://groups.google.com/forum/#!forum/nwcommands/join

Page 3: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

http://nwcommands.org

Page 4: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

GitHub https://github.com/ThomasGrund/nwcommands

Page 5: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

http://nwcommands.org

Page 6: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

Getting started

Page 7: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com
Page 8: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com
Page 9: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com
Page 10: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com
Page 11: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com
Page 12: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

Describe networks

Page 13: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com
Page 14: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com
Page 15: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com
Page 16: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

1

0

gla

sgo

w1

0 1glasgow2

maximum: 2328

frequency

glasgow1

Page 17: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

3

2

1

from

_sm

oke

1

1 2 3to_smoke1

maximum: 71

frequency

glasgow1

Page 18: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

Manipulate networks

Page 19: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com
Page 20: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

. nwclear

. nwrandom 7, density(.2) name(first)

. nwrandom 7, density(.3) name(second)

. nwrandom 7, density(.3) name(third)

. gen attr= _n * 2

// replacing networks

. nwreplace first = 1

. nwreplace first = 2 in 3/5

. nwreplace first = exp(second) * attr if first == 1

// replacing subnetworks

. nwreplace first[(2::6),(1::5)] = 55

. nwreplace first[(1::4),(1::4)] = second * 7 if third != 1

// replacing with temporary networks

. nwreplace first = 99 * (_nwrandom 7, prob(.3))

Page 21: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

Analyze networks

Page 22: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com
Page 23: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

Network permutation

permutation

- 1 1 0

1 - 0 1

1 0 - 0

0 0 0 -

- 0 0 0

0 - 0 1

1 0 - 1

0 1 1 -

Page 24: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

05

10

15

den

sity

-.2 0 .2 .4 .6correlation

based on 50 QAP permutations of network glasgow1

Corr(glasgow1, glasgow2)

Page 25: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

05

10

15

den

sity

-.1 -.05 0 .05 .1correlation

based on 50 QAP permutations of network glasgow1

Corr(glasgow1, same_sport1)

Page 26: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com
Page 27: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

Exponential random graph models

logit 𝑃 𝑌𝑖𝑗 = 1 𝑛 𝑎𝑐𝑡𝑜𝑟𝑠, 𝑌𝑖𝑗𝑐 = 𝜃𝑘𝛿𝑠𝑘 𝒚

𝐾

𝑘=1

Probability that there is a tie from i

to j. Given, n actors AND the rest of the network, excluding the dyad

in question!

𝑌𝑖𝑗𝑐 = all dyads other than 𝑌𝑖𝑗 Amount by which the feature

𝑠𝑘 𝑦 changes when 𝑌𝑖𝑗 is

toggled from 0 to 1.

Page 28: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com
Page 29: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

0

.1.2

.3.4

perc

enta

ge o

f nodes

0 2 4 6 8 10 12indegree

0.1

.2.3

.4

perc

enta

ge o

f nodes

0 2 4 6 8 10outdegree

0.2

.4.6

.81

perc

enta

ge o

f nodes

1 1.5 2 2.5 3 3.5 4edge-wise shared partners

0.2

.4.6

.81

perc

enta

ge o

f nodes

1 1.5 2 2.5 3 3.5 4minimum geodesic distance

based on 30 simulations

goodness-of-fit

Page 30: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

-5

0

05

0

edg

es

0 500000 1000000step

0

.01

.02

.03

den

sity

-50 0 50edges

-20-1

0 01

020

mutu

al

0 500000 1000000step

0

.02

.04

.06

den

sity

-20 -10 0 10 20mutual

-40-2

0 02

040

nod

em

atc

h.s

mo

ke1

0 500000 1000000step

0

.01

.02

.03

.04

den

sity

-40 -20 0 20 40nodematch.smoke1

MCMC-diagnostics

Page 31: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

Visualize networks

Page 32: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com
Page 33: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

http://nwcommands.wordpress.com/nwcmovie

Page 34: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

. nwuse gomery, nwclear

. nwmovie _all, color(col_t*) scheme(s2network)

http://nwcommands.wordpress.com/nwcmovie

Page 35: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

. nwuse gang, nwclear

. nwplot, color(Birthplace) scheme(s2network)

Page 36: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

. nwplot, size(Arrests, forcekeys(5 15 30)) color(Birthplace)

symbol(Prison)

Page 37: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

. nwuse florentine, nwclear

. nwplot flobusiness, label(_label) edgecolor(flomarriage)

edgecolorpalette(yellow red) title(“Florentine

Businesses”, color(red) size(huge))

Page 38: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

. nwuse glasgow, nwclear

. nwmovie _all

http://nwcommands.wordpress.com/demo_nwplot

Page 39: SOCIAL NETWORK ANALYSIS USING STATA · SOCIAL NETWORK ANALYSIS USING STATA 5 Sept 2014, Aarhus Nordic and Baltic Stata Group Meeting Thomas Grund Linköping University thomas.u.grund@gmail.com

http://nwcommands.org

Thomas Grund Linköping University [email protected] www.grund.co.uk