1 Star 0 Fork 7

夏汉林/nwcommands

forked from 连享会/nwcommands 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
nw2set.ado 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
ThomasGrund 提交于 2015-12-10 10:45 . v1.6.4
capture program drop nw2set
program nw2set
syntax [varlist (default=none)][, generate(string) rownames(varname) xvars name(string) clear nwclear edgelist name(string) vars(string) labs(string) mat(string) ]
set more off
if "`clear'" != "" {
nwdrop _all, netonly
}
if "`nwclear'" != "" {
nwclear
}
if "`generate'" == "" {
local generate = "_modeid"
}
if "`edgelist'" != "" {
qui foreach var in `varlist' {
tostring(`var'), replace
}
nw2fromedge `varlist', generate(`generate') `xvars' name(`name')
exit
}
capture mata: mata drop M
if "`mat'" != "" {
mata: M = J((rows(`mat') + cols(`mat')), (rows(`mat') + cols(`mat')), 0)
mata: M[((cols(`mat') + 1) :: rows(M)), (1:: cols(`mat'))] = `mat'
mata: M = M + M'
}
// matrix given in varlist
else {
tempname mat
qui putmata `mat' = (`varlist')
mata: M = J((rows(`mat') + cols(`mat')), (rows(`mat') + cols(`mat')), 0)
mata: M[((cols(`mat') + 1) :: rows(M)), (1:: cols(`mat'))] = `mat'
mata: M = M + M'
mata: mata drop `mat'
local rows ""
forvalues i=1/`=_N' {
if "`rownames'" != "" {
local new = "`=`rownames'[`i']'"
local new = strtoname("`new'")
local rows "`rows' `new'"
}
else {
local rows "`rows' n`i'"
}
}
local l "`varlist' `rows'"
}
if "`labs'" != "" {
local l "`labs'"
}
local mode1 : word count `varlist'
qui nwset, mat(M) labs(`l') vars(`l') name(`name') undirected `xvars'
qui nwload, labelonly
capture drop `rownames'
capture drop `generate'
capture drop `varlist'
generate `generate' = 2 - (_n <= `mode1')
mata: mata drop M
end
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xiahanlin/nwcommands.git
git@gitee.com:xiahanlin/nwcommands.git
xiahanlin
nwcommands
nwcommands
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385