Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Andrew Musau - I have 116,000 student-class observations, so when I ran your code, adjusted to my data, I stopped the computation process some 15 minutes. I think it will work great like in the example in the thread, but not in my case, unfortunately.
    The looping solution is time inefficient as you are filling in the entries of the matrix one at a time. If the matrix is of dimension 696 \(\times\) 696, you will be loading the data set 484,416 times, so it will definitely take more than 15 minutes to run. However, if you are patient enough, you will get there at the end. I gather from #13 that Mike Lacy's solution in the same thread did work, so you should stick to that. If you just need to rename the columns the same as the rows, then this is straightforward. Here is an example.

    Code:
    mat A= J(7, 7, 7)
    mat l A
    local rownames: rown A
    mat colnames A= `rownames'
    mat l A
    Res.:

    Code:
    . mat A= J(7, 7, 7)
    
    . 
    . mat l A
    
    symmetric A[7,7]
        c1  c2  c3  c4  c5  c6  c7
    r1   7
    r2   7   7
    r3   7   7   7
    r4   7   7   7   7
    r5   7   7   7   7   7
    r6   7   7   7   7   7   7
    r7   7   7   7   7   7   7   7
    
    . 
    . local rownames: rown A
    
    . 
    . mat colnames A= `rownames'
    
    . 
    . mat l A
    
    symmetric A[7,7]
        r1  r2  r3  r4  r5  r6  r7
    r1   7
    r2   7   7
    r3   7   7   7
    r4   7   7   7   7
    r5   7   7   7   7   7
    r6   7   7   7   7   7   7
    r7   7   7   7   7   7   7   7

    Comment


    • #17
      Mikhail Balaev : Going back to your post at #13:

      1) How to rename variables? See -help rename group-
      Code:
      rename attend* exam_code
      2) My code that you used will *not* necessarily produce observations for all pairings of classes (exam_code in your variable naming scheme). Suppose, for example, that the class with exam_code = 99 did not share any students in common with the class with exam_code = 77. In that case, the -joinby- command will not create an observation for that pair.

      3) It appears that you are exporting a matrix to Excel in order to complete some centrality or similar calculation there. That would not be necessary, as those calculations can almost certainly be done in Stata. However, for many calculations, having the data in an actual matrix in Stata or better yet in Mata will likely be preferable to trying to work on it as a Stata data set.

      4) Last and perhaps most important: Your 696 X 696 adjacency matrix created as a Stata data set can be made into a network object in -nwcommands- without any memory issues, and centrality etc. can be calculated easily. Here's an example:

      Code:
      clear
      // Simulate your 696 X 696 data set
      local maxstudent = 10
      set obs 696
      gen int exam_code = _n
      forval i = 1/696 {
         gen int exam_code`i'= trunc((`maxstudent' + 1) * runiform())
      }
      //
      // -nwcommands- command to make a network from a data set
      nwset exam_code1 - exam_code696
      //  Eigenvector centrality, very fast
      nwevcent network, generate(_evcent)
      // Betweeness centrality, took about 5-10 minutes
      nwbetween network, generate(_between)

      Comment

      Working...
      X