Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: egen and Mata


From   "Stas Kolenikov" <skolenik@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: egen and Mata
Date   Wed, 16 Jul 2008 16:31:06 -0500

If I had an additional information that -groupid- goes from 1 to G,
would something like this work? I am sure this can be optimized, but I
wonder if my Mata thinking is reasonable. At least this code avoids
sorting operations.

selectvar = J(rows(id),1,.)

for(g=1;g<=G;g++) {
   // take a subview corresponding to value of g
  selectvar = ! ( id - J(rows(id),1,g) )
  st_select(thisy=.,y, selectvar)
  st_select(yy2=.,y2,selectvar)
  yy2[,]=J(rows(yy2),1,colmean(thisy))
}

-panelsetup- is probably a more elegant solution, I've never tried it!

-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: Please do not reply to my Gmail address as I don't check
it regularly.
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index