代码拉取完成,页面将自动刷新
同步操作将从 连享会/nwcommands 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
*! Date : 3sept2014
*! Version : 1.0.1
*! Author : Thomas Grund, Linkoping University
*! Email : contact@nwcommands.org
capture program drop nwset
program nwset
syntax [varlist (default=none)][, keeporiginal xvars clear nwclear nooutput edgelist name(string) vars(string) labs(string) labsfromvar(string) abs(string asis) edgelabs(string asis) detail mat(string) undirected directed]
set more off
if "`edgelist'" != "" {
local labsfromvar ""
}
if "`clear'" != "" {
nwdrop _all, netonly
exit
}
if "`nwclear'" != "" {
nwclear
exit
}
local numnets = 0
mata: st_rclear()
local max_nodes = 0
local allnames ""
qui if "`edgelist'" != "" {
qui nwfromedge `varlist', name(`name') `xvars' `keeporiginal' `undirected'
exit
}
// display information about network
if ("`varlist'" == "" & "`mat'" == "") {
if ("$nwtotal" == "" | "$nwtotal" == "0") {
mata: st_numscalar("r(networks)", 0)
noi di "{err}No network found."
error 6001
}
else {
if ("`output'" != "nooutput") {
local networks = plural($nwtotal, "network")
di "{txt}($nwtotal `networks')"
// information about networks
if "`detail'" == "" {
di "{hline 20}"
}
forvalues i=1/`=$nwtotal'{
scalar onesize = "\$nwsize_`i'"
local thissize `=onesize'
local max_nodes = max(`max_nodes', `thissize')
scalar onename = "\$nwname_`i'"
local allnames "`allnames' `=onename'"
scalar onenw = "\$nw_`i'"
scalar onelabs = "\$nwlabs_`i'"
local l `"`=onelabs'"'
scalar onedirected = "\$nwdirected_`i'"
scalar oneedgelabs = "\$nwedgelabs_`i'"
if "`detail'" != "" {
di
di "{hline 50}"
if (`i' == $nwtotal){
di "{txt} `i') Current Network"
}
else {
di "{txt} `i') Stored Network"
}
di "{hline 50}"
di "{txt} Network name: {res}`=onename'"
di "{txt} Directed: {res}`=onedirected'"
di "{txt} Nodes: {res}`=onesize'"
di "{txt} Network id: {res}`i'"
di "{txt} Variables: {res}`=onenw'"
di `"{txt} Labels: {res}`=onelabs'"'
di `"{txt} Edgelabels: {res}`=oneedgelabs'"'
}
else {
di " {res}`=onename'"
}
}
}
}
}
// set the network
else {
// set network from varlist
if "`varlist'" != "" {
local varscount : word count `vars'
local labscount : word count `labs'
local varlistcount: word count `varlist'
if (`varlistcount' > _N ) {
unab A : _all
local newvarlist ""
forvalues j = 1/`=_N' {
local newvar : word `j' of `varlist'
local newvarlist "`newvarlist' `newvar'"
}
local varlist `newvarlist'
}
local size: word count `varlist'
qui nwtomata `varlist', mat(onenet)
local mat = "onenet"
if (`varscount' != `size') unab vars: `varlist'
if (`labscount' != `size') local labs "`vars'"
}
// set network from mata matrix
else {
// either varlist or mat needs to be given
if ("`mat'" == ""){
di "{err}either {it:varlist} or option {it:mat()} needs to be specfied"
exit
}
// mat is given
else {
/*capture mat list `mat'
if _rc == 0 {
mata: `mat' = st_matrix("`mat'")
}*/
mata: onenet = `mat'
mata: st_numscalar("msize", rows(`mat'))
local size = msize
local varscount : word count `vars'
local labscount : word count `labs'
// generate vars"
if("`varscount'" != "`size'"){
local vars ""
forvalues i = 1/`size' {
local vars "`vars' var`i'"
}
}
// get labels
if (`labscount' != `size'){
local labs "`vars'"
}
}
}
if "`name'" == "" {
local name "network"
}
nwvalidate `name'
local name = r(validname)
if "$nwtotal" == "" {
global nwtotal 0
}
local directed_new = "true"
if "`undirected'" != "" {
local directed_new = "false"
}
if"`directed'" != "" {
local directed_new = "true"
}
local new_nwtotal = $nwtotal + 1
mata: nw_mata`new_nwtotal' = onenet
global nw_`new_nwtotal' "`vars'"
global nwlabs_`new_nwtotal' `"`labs'"'
global nwedgelabs_`new_nwtotal' `"`edgelabs'"'
global nwsize_`new_nwtotal' "`size'"
global nwname_`new_nwtotal' "`name'"
global nwdirected_`new_nwtotal' "`directed_new'"
global nwtotal = `new_nwtotal'
global nwtotal_mata = $nwtotal
mata: mata drop onenet
}
if "`labsfromvar'" != "" {
nwname `name', newlabsfromvar(`labsfromvar')
}
mata: st_rclear()
mata: st_numscalar("r(networks)", $nwtotal)
mata: st_numscalar("r(max_nodes)", `max_nodes')
mata: st_global("r(names)", "`allnames'")
end
*! v1.5.0 __ 17 Sep 2015 __ 13:09:53
*! v1.5.1 __ 17 Sep 2015 __ 14:54:23
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。