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 in Stata


From   jean-luc morin-chesnel <[email protected]>
To   [email protected]
Subject   Re: st: Adjacency matrix in Stata
Date   Mon, 31 Mar 2014 11:07:10 +0200

Thank you Brendan, this is pure genius!!!

On 31 March 2014 00:23, Brendan Halpin <[email protected]> wrote:
> I wouldn't use Stata matrices here. You can use Stata data sets instead,
> with very little limit as regards number of cases, if you structure your
> data as (person_i, person_j, X), where X is a variable representing the
> strength of the link (e.g., the count of times the same product is
> bought on the same day).
>
> Start by creating a data set at individual level, with key variables
> product and date. Duplicate it, changing the name of the person-ID
> variable in the second. Then do a many-to-many merge using the
> product and date as the key, so that you end up with a person_i/person_j pair for
> every time they bought the same product on the same day. Then use, for
> instance, -collapse- to sum the number of common purchases, delete cases
> below your threshold, delete the cases here individuals are matched to
> themselves, and you have your adjacency matrix. It's in I/J/X format,
> rather than the very sparse square matrix, but the all information is
> there.
>
> I don't know what you want to do with it, but network analysis commonly
> works with adjacency matrices represented like this, because it is
> efficient.
>
> Brendan
>
>
> Example (untested), if purchases.dta has variables id, product and date:
>
> use purchases
> rename id idj
> merge m:m product date using purchases
>
> drop if id==idj
> sort id idj
> gen n = 1
> collapse (sum) n, by(id idj)
> keep if n>=10
>
>
>
> --
> Brendan Halpin, Head, Department of Sociology, University of Limerick, Ireland
> Tel: w +353-61-213147  f +353-61-202569  h +353-61-338562;  Room F1-002 x 3147
> mailto:[email protected]    ULSociology on Facebook: http://on.fb.me/fjIK9t
> http://teaching.sociology.ul.ie/bhalpin/wordpress         twitter:@ULSociology
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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