. * nwrem tutorial 2: covariates, pair covariates and recency . * Requires the core nwcommands and the package nwrem. . * Run from this folder; the data are in ../data. . . * --- declare the events (see tutorial 1) --- . import delimited "../data/calls_actors.csv", clear (encoding automatically selected: ISO-8859-2) (3 vars, 84 obs) . tempfile actors . save `actors' file /var/folders/hx/2zp2k5ps2y7d_6hx015fcr1h0000gn/T//S_11080.000001 saved as .dta format . import delimited "../data/calls_events.csv", clear (encoding automatically selected: ISO-8859-1) (3 vars, 439 obs) . levelsof sender, local(a) clean 1 2 5 7 8 11 16 20 21 23 24 27 29 30 31 32 36 37 42 43 44 46 47 51 55 58 62 64 66 67 68 70 71 72 . levelsof receiver, local(b) clean 1 3 4 6 8 9 11 12 14 16 20 21 22 23 24 25 27 30 31 32 33 34 35 36 42 43 44 45 46 50 51 54 55 58 60 61 63 64 66 67 68 70 > 71 74 76 77 . local all : list a | b . local miss . forvalues i = 1/84 { 2. if !`: list i in all' local miss `miss',`i' 3. } . local miss = substr("`miss'", 2, .) . nwset sender receiver, directed eventtime(eventtime) name(calls) . nwaddnodes calls, nodenames(`miss') . . * --- actor attributes, one row per actor in the actor order of the network --- . nwload calls, xvars . gen long actor = real(subinstr(_nwnode, "n", "", 1)) . gen long row = _n . merge m:1 actor using `actors', keep(master match) nogenerate Result Number of obs ----------------------------------------- Not matched 0 Matched 84 ----------------------------------------- . sort row . list _nwnode actor floor in 1/4 +-------------------------+ | _nwnode actor floor | |-------------------------| 1. | n1 1 3 | 2. | n2 2 5 | 3. | n3 3 5 | 4. | n4 4 2 | +-------------------------+ . list _nwnode actor floor in 55/58 +-------------------------+ | _nwnode actor floor | |-------------------------| 55. | 10 10 9 | 56. | 13 13 5 | 57. | 15 15 7 | 58. | 17 17 4 | +-------------------------+ . . * --- pair covariate: 1 if two students live on the same floor --- . mata: ------------------------------------------------- mata (type end to exit) ---------------------------------------------- : F = st_data(., "floor") : n = rows(F) : S = J(n, n, 0) : for (i = 1; i <= n; i++) { > for (j = 1; j <= n; j++) S[i, j] = (i != j) & (F[i] == F[j]) > } : end ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- . nwset, mat(S) name(sameflr) directed . nwset (2 networks) -------------------- calls sameflr . . * --- history of the pair (the model of tutorial 1) and actor covariates --- . nwrem calls, frpsndsnd frrecsnd ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Relational event model (ordinal partial likelihood, MLE) Network: calls Actors: 84 Events: 439 Log likelihood: -2.27e+03 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- calls | Coefficient Std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- frpsndsnd | 6.254317 .1453013 43.04 0.000 5.969532 6.539103 frrecsnd | 2.034607 .140024 14.53 0.000 1.760165 2.309049 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- . estimates store hist . nwrem calls, frpsndsnd frrecsnd covsnd(floor) covrec(floor) ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Relational event model (ordinal partial likelihood, MLE) Network: calls Actors: 84 Events: 439 Log likelihood: -2.20e+03 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- calls | Coefficient Std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- frpsndsnd | 6.134409 .1464316 41.89 0.000 5.847408 6.42141 frrecsnd | 1.562276 .1440921 10.84 0.000 1.279861 1.844692 covsnd_floor | -.2432981 .0274013 -8.88 0.000 -.2970036 -.1895926 covrec_floor | -.1703417 .0256821 -6.63 0.000 -.2206777 -.1200057 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- . estimates store floors . nwrem calls, frpsndsnd frrecsnd covevent(sameflr) ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Relational event model (ordinal partial likelihood, MLE) Network: calls Actors: 84 Events: 439 Log likelihood: -2.26e+03 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- calls | Coefficient Std. err. z P>|z| [95% conf. interval] -----------------+---------------------------------------------------------------- frpsndsnd | 6.390339 .1469765 43.48 0.000 6.10227 6.678407 frrecsnd | 2.013556 .1389282 14.49 0.000 1.741262 2.28585 covevent_sameflr | -.5312484 .1219874 -4.35 0.000 -.7703393 -.2921574 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- . estimates store samefloor . . * --- recent instead of frequent --- . nwrem calls, rsndsnd rrecsnd ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Relational event model (ordinal partial likelihood, MLE) Network: calls Actors: 84 Events: 439 Log likelihood: -2.12e+03 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- calls | Coefficient Std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- rsndsnd | 6.417377 .1430789 44.85 0.000 6.136947 6.697806 rrecsnd | 1.599738 .1220665 13.11 0.000 1.360493 1.838984 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- . estimates store recent . nwrem calls, frpsndsnd frrecsnd rsndsnd rrecsnd ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Relational event model (ordinal partial likelihood, MLE) Network: calls Actors: 84 Events: 439 Log likelihood: -2.09e+03 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- calls | Coefficient Std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- frpsndsnd | 1.193429 .2271175 5.25 0.000 .7482867 1.638571 frrecsnd | .7568561 .3607762 2.10 0.036 .0497478 1.463964 rsndsnd | 5.475211 .236147 23.19 0.000 5.012372 5.938051 rrecsnd | .9312852 .3498345 2.66 0.008 .2456222 1.616948 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- . estimates store both . . estimates table hist floors samefloor recent both, b(%9.3f) stats(ll N) ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Variable | hist floors samefloor recent both -------------+------------------------------------------------------------ frpsndsnd | 6.254 6.134 6.390 1.193 frrecsnd | 2.035 1.562 2.014 0.757 covsnd_floor | -0.243 covrec_floor | -0.170 covevent_s~r | -0.531 rsndsnd | 6.417 5.475 rrecsnd | 1.600 0.931 -------------+------------------------------------------------------------ ll | -2274.048 -2197.731 -2263.785 -2122.016 -2094.776 N | 439 439 439 439 439 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- . lrtest floors hist Likelihood-ratio test Assumption: hist nested within floors LR chi2(2) = 152.63 Prob > chi2 = 0.0000 . lrtest both hist Likelihood-ratio test Assumption: hist nested within both LR chi2(2) = 358.54 Prob > chi2 = 0.0000 .