mcaceresb / stata-gtools

Faster implementation of Stata's collapse, reshape, xtile, egen, isid, and more using C plugins
https://gtools.readthedocs.io
MIT License
182 stars 38 forks source link

the option cw in gcollapse is invalid. #82

Closed Meiting-Wang closed 2 years ago

Meiting-Wang commented 3 years ago

Describe the bug

clear
cls
input id year x y z
    1 2000 3 5 6
    1 2001 5 6 8
    1 2002 3 9 7
    2 2001 7 11 12
    2 2002 7 16 9
    2 2003 7 11 15
    2 2004 9 11 12
    3 2000 12 16 14
    3 2001 19 22 11
    4 2003 3 6 .
    4 2004 4 9 10
end

preserve
gcollapse (mean) m_x=x m_y=y m_z=z, cw
list
restore

preserve
collapse (mean) m_x=x m_y=y m_z=z, cw
list
restore

. input id year x y z

             id        year           x           y           z
  1.         1 2000 3 5 6
  2.         1 2001 5 6 8
  3.         1 2002 3 9 7
  4.         2 2001 7 11 12
  5.         2 2002 7 16 9
  6.         2 2003 7 11 15
  7.         2 2004 9 11 12
  8.         3 2000 12 16 14
  9.         3 2001 19 22 11
 10.         4 2003 3 6 .
 11.         4 2004 4 9 10
 12. end

. 
. preserve

. gcollapse (mean) m_x=x m_y=y m_z=z, cw

. list

     +------------------------------+
     |       m_x         m_y    m_z |
     |------------------------------|
  1. | 7.1818182   11.090909   10.4 |
     +------------------------------+

. restore

. 
. preserve

. collapse (mean) m_x=x m_y=y m_z=z, cw

. list

     +-------------------+
     | m_x    m_y    m_z |
     |-------------------|
  1. | 7.6   11.6   10.4 |
     +-------------------+

. restore

. 
end of do-file

. 

Version info

mcaceresb commented 3 years ago

This is solved in the latest develop build. Will merge to master soon. Please run

gtools, upgrade branch(develop)

And check you are using version 1.8.3 via which gtools.

Meiting-Wang commented 3 years ago

This is solved in the latest develop build. Will merge to master soon. Please run

gtools, upgrade branch(develop)

And check you are using version 1.8.3 via which gtools.

Thank you👍