Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcollapse fails with a large number of targets or by variables #7

Closed
mcaceresb opened this issue Aug 3, 2017 · 1 comment
Closed
Assignees

Comments

@mcaceresb
Copy link
Owner

gcollapse will give an error when there are too many by variables or targets. The number of targets and by variables are limited by matsize:

clear
set matsize 100
set obs 10
forvalues i = 1/101 {
    gen x`i' = 10
}
gen zz = runiform()
gcollapse zz, by(x*)
gcollapse x*, by(zz)

Both commands above will fail with error code 908. However, there is a point where increasing matsize will not help with the number of targets:

clear
set matsize 400
set obs 10
forvalues i = 1/300 {
    gen x`i' = 10
}
gen zz = runiform()
gcollapse zz, by(x*)
gcollapse x*, by(zz)

The first command will succeed but the second will fail with error code 3000 (too many tokens). This is a problem with lines 253-255, 314, 385, 487, 514, 570, 579, and 621 using the regular subinstr function rather than the extended macro function :subinstr. A previous commit had switched to using :subinstr for all locals, but these lines use the function to create a mata object.

NOTE: The matsize problem may be a very fundamental limitation. Make sure to create a warning if it cannot be bypassed.

@mcaceresb mcaceresb added the bug label Aug 3, 2017
@mcaceresb mcaceresb self-assigned this Aug 3, 2017
@mcaceresb
Copy link
Owner Author

The above commands will no longer fail. This is now only a problem when Stata hits the matsize limit. So this is fine:

clear
set obs 10
forvalues i = 1/800 {
    gen x`i' = 10
}
gen zz = runiform()
preserve
    gcollapse zz, by(x*) `options'
restore, preserve
    gcollapse x*, by(zz) `options'
restore

But this fails

gen x801 = 10
preserve
    collapse zz, by(x*) `options'
restore, preserve
    collapse x*, by(zz) `options'
restore

However, the error message specifies it is a matsize limitation and tells the user how they might be able to fix it.

@mcaceresb mcaceresb added enhancement and removed bug labels Sep 13, 2017
mcaceresb added a commit that referenced this issue Sep 13, 2017
Bug fixes

* Improves the issues raised by #7
  Now the commands only fail if Stata hits the `matsize` limit (internally, the plugin
  no longer uses the `subinstr` hack to go from locals to mata string matrices and uses
  `tokens` instead, which is more appropriate; further, the plugin tries to set matsize
  to at least the number of variables and gives a verbose error if it fails.)
mcaceresb added a commit that referenced this issue Sep 13, 2017
gtools-0.6.16 (2017-09-13)

* Improves the issues raised by #7
  Now the commands only fail if Stata hits the `matsize` limit (internally,
  the plugin no longer uses the `subinstr` hack to go from locals to mata
  string matrices and uses `tokens` instead, which is more appropriate;
  further, the plugin tries to set matsize to at least the number of variables
  and gives a verbose error if it fails).
* No longer crashes on Linux systems with older glibc versions.
* Fixes #14
* Should fix #12
* Fixes #9
* Fixed #8
  `gegen` is callable via `by:`; it also gives the stat for the
  overall group if called without a `by`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant