Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: adjacency matrix from neighbors for sppack


From   László Sándor <[email protected]>
To   [email protected]
Subject   Re: st: adjacency matrix from neighbors for sppack
Date   Sat, 23 Apr 2011 09:50:27 -0400

I am sorry I missed Rafal's generous reply before -- I overlooked it
as a new message to Statalist, not a reply.

In any case, I tried to do what instructed us to do, but I got what I
think is a Mata error, perhaps about a missing function. I would be
grateful if you could verify that from the echo (with trace on) below.
I just reinstalled -sppack- before the attempt, so if the function is
missing, it is missing from the latest version.

Thank you again,

Laszlo

Mail
Contacts
Tasks
Compose mail
Priority Inbox
Inbox
Buzz (44)
Sent Mail
Drafts (112)
Spam (8)
Raj

36 more▼
Send SMS
You are not signed into chat and SMS
Sign in
Chat


László Sándor
Sign into chat
	Call phone
	Adam Guren
	András Várkonyi
	Dana Rotz
	Devon Stewart
	Gábor Lipcsei
	Jessica Laird
	Márton Bárány
	Mihály Kálmán
	Orsolya Mednyánszky
	Raj Chetty
	Ricardo Nicolás Pérez Truglia
	Syon Bhanot
	Szabolcs Boronkai
	Tamás Szigeti
	Ugo Troiano
Web Search
Quick Links
Follow Upx
Holdx
Add Quick Link
Google Calendar
Invite a friend
><
About these ads
Tired of Java, C++, C#? - Try Eiffel: simple and powerful Another
approach for better results - www.eiffel.com
« Back to Sent MailArchiveReport spamDelete
Move to InboxLabels More actions
‹ Newer 5 of 12095 Older ›
st: adjacency matrix from neighbors for sppack
[email protected] ✆	
Hi Laszlo, I responed to the Statalist yesterday afternoon http://www.stata.c...
11:37 AM (22 hours ago)
Reply to all
László Sándor ✆ to rraciborski
show details 12:06 PM (21 hours ago)
I am really sorry, somehow the reply did not show up in the same
thread in GMail, though it usually does.

And I somehow did not realize from the working paper that the import
function can be useful even if I 'already have' the data as Stata
variables. The documentation in Section 15 did not suggest that, and I
did not make the connection with later examples. I could have had been
that creative.

But in short: I am greatly indebted for the tools and the help.

Thank you!

Laszlo
- Show quoted text -
 Reply
 Forward
Reply to all
László Sándor ✆ to rraciborski
show details 7:23 PM (14 hours ago)
Also, sorry, Rafal, but I got the error below from -spmat-, which I
cannot parse. The result of trace seems to suggest a Mata error, maybe
a missing function. Is that possible? I just reinstall -sppack- today.

Below is the relevant echo with trace on.

Thank you very much,

Laszlo

. spmat import adjmat using friends.raw, nlist replace
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
begin spmat ---
- version 11.1
- gettoken sub 0 : 0 , parse(" ,")
- local len = length(`"`sub'"')
= local len = length(`"import"')
- if `len'==0 {
= if 6==0 {
  di as err "No subcommand specified"
  exit 198
  }
- if `"`sub'"'==substr("idistance",1,max(5,`len')) {
= if `"import"'==substr("idistance",1,max(5,6)) {
  SPMAT_idistance `0'
  }
- else if `"`sub'"'==substr("contiguity",1,max(3,`len')) {
= else if `"import"'==substr("contiguity",1,max(3,6)) {
  cap noi SPMAT_contiguity `0'
  SPMAT_drop_tempnames `matanames'
  }
- else if `"`sub'"'==substr("use",1,max(3,`len')) {
= else if `"import"'==substr("use",1,max(3,6)) {
  SPMAT_read `0'
  }
- else if `"`sub'"'==substr("import",1,max(2,`len')) {
= else if `"import"'==substr("import",1,max(2,6)) {
- SPMAT_import `0'
= SPMAT_import  adjmat using friends.raw, nlist replace
  ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
begin spmat.SPMAT_import ---
  - syntax name using/, [ noID nlist geoda NORMalize(string) IDISTance replace ]
  - if ("`nlist'"=="nlist" & "`idistance'"=="idistance") {
  = if ("nlist"=="nlist" & ""=="idistance") {
    di "{err}idistance not allowed with nlist"
    exit(498)
    }
  - if ("`id'"!="" & "`nlist'"=="nlist") {
  = if (""!="" & "nlist"=="nlist") {
    di "{err}option {cmd:noid} not allowed with nlist"
    exit 498
    }
  - if ("`id'"!="" & "`geoda'"!="") {
  = if (""!="" & ""!="") {
    di "{err}option {cmd:noid} not allowed with geoda"
    exit 498
    }
  - SPMAT_normparse, `normalize'
  = SPMAT_normparse,
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
begin spmat.SPMAT_normparse ---
    - capture syntax , [row SPEctral MINmax]
    - if _rc {
      local 0 : subinstr local 0 "," ""
      di as err `"{cmd:normalize(`0')} invalid"'
      exit 498
      }
    - if "`row'" != "" {
    = if "" != "" {
      return local normalize "row"
      exit
      }
    - else if "`spectral'" != "" {
    = else if "" != "" {
      return local normalize "spectral"
      exit
      }
    - else if "`minmax'" != "" {
    = else if "" != "" {
      return local normalize "minmax"
      exit
      }
    - else {
    - return local normalize
    - }
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
end spmat.SPMAT_normparse ---
  - local normalize `r(normalize)'
  = local normalize
  - if "`replace'" != "" {
  = if "replace" != "" {
  - capture spmat drop `namelist'
  = capture spmat drop adjmat
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
begin spmat ---
    - version 11.1
    - gettoken sub 0 : 0 , parse(" ,")
    - local len = length(`"`sub'"')
    = local len = length(`"drop"')
    - if `len'==0 {
    = if 4==0 {
      di as err "No subcommand specified"
      exit 198
      }
    - if `"`sub'"'==substr("idistance",1,max(5,`len')) {
    = if `"drop"'==substr("idistance",1,max(5,4)) {
      SPMAT_idistance `0'
      }
    - else if `"`sub'"'==substr("contiguity",1,max(3,`len')) {
    = else if `"drop"'==substr("contiguity",1,max(3,4)) {
      cap noi SPMAT_contiguity `0'
      SPMAT_drop_tempnames `matanames'
      }
    - else if `"`sub'"'==substr("use",1,max(3,`len')) {
    = else if `"drop"'==substr("use",1,max(3,4)) {
      SPMAT_read `0'
      }
    - else if `"`sub'"'==substr("import",1,max(2,`len')) {
    = else if `"drop"'==substr("import",1,max(2,4)) {
      SPMAT_import `0'
      }
    - else if `"`sub'"'==substr("export",1,max(2,`len')) {
    = else if `"drop"'==substr("export",1,max(2,4)) {
      SPMAT_export `0'
      }
    - else if `"`sub'"'==substr("save",1,max(2,`len')) {
    = else if `"drop"'==substr("save",1,max(2,4)) {
      SPMAT_save `0'
      }
    - else if `"`sub'"'=="drop" {
    = else if `"drop"'=="drop" {
    - SPMAT_drop `0'
    = SPMAT_drop  adjmat
      -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
begin spmat.SPMAT_drop ---
      - capture syntax name
      - capture mata : SPMAT_assert_object("`namelist'")
      = capture mata : SPMAT_assert_object("adjmat")
      - local rc = _rc
      - capture mata : mata drop `namelist'
      = capture mata : mata drop adjmat
      - if (`rc') di "{txt}(note: spmat object {cmd:`namelist'} not found)"
      = if (3499) di "{txt}(note: spmat object {cmd:adjmat} not found)"
      ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
end spmat.SPMAT_drop ---
    - }
    - else if `"`sub'"'==substr("graph",1,max(2,`len')) {
    = else if `"drop"'==substr("graph",1,max(2,4)) {
      SPMAT_graph `0'
      }
    - else if `"`sub'"'==substr("putmatrix",1,max(6,`len')) {
    = else if `"drop"'==substr("putmatrix",1,max(6,4)) {
      SPMAT_putmatrix `0'
      }
    - else if `"`sub'"'==substr("getmatrix",1,max(6,`len')) {
    = else if `"drop"'==substr("getmatrix",1,max(6,4)) {
      SPMAT_getmatrix `0'
      }
    - else if `"`sub'"'==substr("permute",1,max(3,`len')) {
    = else if `"drop"'==substr("permute",1,max(3,4)) {
      SPMAT_permute `0'
      }
    - else if `"`sub'"'==substr("dta",1,max(3,`len')) {
    = else if `"drop"'==substr("dta",1,max(3,4)) {
      cap noi SPMAT_dta `0'
      SPMAT_drop_tempnames `matanames'
      }
    - else if `"`sub'"'==substr("summarize",1,max(2,`len')) {
    = else if `"drop"'==substr("summarize",1,max(2,4)) {
      SPMAT_summarize `0'
      return add
      }
    - else if `"`sub'"'==substr("note",1,max(4,`len')) {
    = else if `"drop"'==substr("note",1,max(4,4)) {
      cap noi SPMAT_note `0'
      SPMAT_drop_tempnames `matanames'
      }
    - else if `"`sub'"'==substr("tobanded",1,max(3,`len')) {
    = else if `"drop"'==substr("tobanded",1,max(3,4)) {
      SPMAT_tobanded `0'
      }
    - else if `"`sub'"'==substr("copy",1,max(4,`len')) {
    = else if `"drop"'==substr("copy",1,max(4,4)) {
      SPMAT_copy `0'
      }
    - else if `"`sub'"'==substr("lag",1,max(3,`len')) {
    = else if `"drop"'==substr("lag",1,max(3,4)) {
      SPMAT_lag `0'
      }
    - else if `"`sub'"'==substr("eigenvalues",1,max(3,`len')) {
    = else if `"drop"'==substr("eigenvalues",1,max(3,4)) {
      SPMAT_eigenvalues `0'
      }
    - else if `"`sub'"'==substr("idmatch",1,max(2,`len')) {
    = else if `"drop"'==substr("idmatch",1,max(2,4)) {
      SPMAT_idmatch `0'
      }
    - else {
      di as error `"`sub' unknown subcommand"'
      exit 198
      }
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
end spmat ---
  - }
  - mata : SPMAT_import_u("`namelist'", `"`using'"', "`id'",
"`nlist'", "`geoda'", "`idistance'","`normalize'")
  = mata : SPMAT_import_u("adjmat", `"friends.raw"', "", "nlist", "", "","")
                 <istmt>:  3499  SPMAT_import_u() not found
  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
end spmat.SPMAT_import ---
  }
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
end spmat ---
r(3499);

On Thu, Apr 21, 2011 at 3:42 PM, <[email protected]> wrote:
>
> László Sándor <[email protected]> has a question about creating an adjacency
> matrix using the user-written command -spmat-:
>
> > I would like to use the -sppack- package for social network analysis....
> > I have IDs of friends for each individual as an observation (variables:
> > friend1-friend10). I would like to repeat basically this exercise, but
> > for -spmat-: http://www.ats.ucla.edu/stat/stata/code/adj_matrix.htm
>
> The data presented on the UCLA page is in what we call a 'neighbor list'
> format, that is, each line lists a student ID followed by the IDs of friends.
>
> As discussed in sections 13.4, 15, and 17.4 of the working paper László referred
> to in his post, we can use -spmat import- with option -nlist- to create an
> adjacency matrix from the above data.  The only requirement is that the friends
> data are in a format that -spmat import- can understand.  The help file for
> -spmat import- states that the data to be imported should be in a
> space-delimited text file and that the option -nlist-
>
>    specifies that the text file is in the neighbor-list format.
>    The first line of the file must contain the total number of
>    places....  Each remaining line lists a place ID followed by
>    its neighbors, if any.
>
> Thus, we first save the data in the friends.txt file in the required format:
>
> -------- begin friends.txt --------
> 10
> 44006 45611 55610 74158 55898
> 45611 44006 45623 45621 74158 55898
> 45621 71643 45611
> 45623 59642 71643 45611 73452 55610
> 55610 45623 45611 44006 55898 71643
> 55898 74158 55610 45621
> 59642 55898 71643 45621 45611 74158
> 71643 55898 73452 59642 45611 44006
> 73452 71643 45623
> 74158 55898 45611 59642 45621 44006
> --------- end friends.txt ---------
>
> Now we are ready to create an adjacency matrix using -spmat import-:
>
>  . spmat import adj using friends.txt, nlist
>
> We created a spatial-weighting object named 'adj' that contains the adjacency
> matrix constructed from the data contained in the file friends.txt.  László can
> verify that the resulting adjacency matrix is identical to the one presented on
> the UCLA page by typing
>
>  . spmat getmatrix adj W id
>  . mata: id, W
>
> --Rafal
> [email protected]
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index