1 Star 1 Fork 7

连享会/nwcommands

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
nwreplacemat.ado 1.79 KB
一键复制 编辑 原始数据 按行查看 历史
ThomasGrund 提交于 2015-09-18 19:13 . v1.5.1
capture program drop nwreplacemat
program nwreplacemat
version 9.0
syntax anything(name=netname), newmat(string) [vars(string) labs(string) nosync netonly xvars]
_nwsyntax `netname', max(1)
capture mat list `newmat'
if _rc == 0 {
mata: `newmat' = st_matrix("`newmat'")
}
mata: st_numscalar("r(matrows)", rows(`newmat'))
mata: st_numscalar("r(matcols)", cols(`newmat'))
local matrows = r(matrows)
local matcols = r(matcols)
// newmat is invalid (not N x X matrix)
if (`matrows' != `matcols'){
di "{err}input matrix has invalid dimensions"
erorr 6082
}
// newmat is of different size than the network
if (`matrows' != `nodes'){
//di "{txt}input matrix has different dimensions than existing {it:network} {bf:`netname'}. size of {bf:`netname'} has been adjusted."
local nodes = `matrows'
if ("`netonly'" != "" | "`sync'" != "") {
mata: `newmat'
mata: nw_mata`id' = `newmat'
global nwsize_`id' = `matrows'
if "`vars'" != "" {
global nw_`id' "`vars'"
}
if "`labs'" != "" {
global nwlabs_`id' "`labs'"
}
}
else {
nwdrop `netname', `netonly'
nwrandom `nodes', prob(1) name(`netname') vars(`vars') labs(`labs') `xvars'
nwreplacemat `netname', newmat(`newmat') `nosync' `xvars'
// delete empty observations in Stata
nwcompressobs
}
}
else {
mata: nw_mata`id' = `newmat'
if "`netonly'" == "" {
if "`sync'" == "" {
nwsync `netname'
}
}
}
// check for directed/undirected of new network and adjust if necessary
mata: st_numscalar("r(directed)", (issymmetric(`newmat') == 1))
if (`r(directed)' == 1) {
global nwdirected_`id' = "false"
}
else {
global nwdirected_`id' = "true"
}
end
*! v1.5.0 __ 17 Sep 2015 __ 13:09:53
*! v1.5.1 __ 17 Sep 2015 __ 14:54:23
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/arlionn/nwcommands.git
git@gitee.com:arlionn/nwcommands.git
arlionn
nwcommands
nwcommands
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385