2

I am using a Stata command, synth, that takes a numlist as an argument.

I need the numlist to take 2,000+ values. Note that forvalues is not a viable work-around in this context, unless I am mistaken. I am using Stata MP 13.1. In help limits it says that the size limit for a numlist is 2,500. However, when I run the following code, I receive error code "r(123) invalid numlist has too many elements."

foreach i of numlist 1/1601 {
   display `i'
}

This code runs without an error:

foreach i of numlist 1600{
    display `i'
}

Is there a way to allow a larger numlist than 1,600 elements? Also, why does help limits tell me I have 2,500 to work with, but not allow more than 1,600?

Edited to add: nlist, used to parse a numlist, specifies a maximum of 1,600. So perhaps 1,600 is the proper maximum? In that case, the help limits page seems to be incorrect.

Second edit to add: synth is a matching command, and you provide it with a numlist of control units to include in the matching procedure. So if you have a panel with 2000 units and 10 time periods, you might specify 1,999 units to be included as potential control units. It might be possible to use forvalues, but it would require editing the synth ado file somewhat significantly.

1
  • numlist "1/2500" works for me in 14.1. I surmise that the limit that is biting you is an undocumented limit for foreach (which I agree should be documented as such). I can't comment on synth and in any case you should say more about how a numlist is used with synth.
    – Nick Cox
    Nov 19, 2015 at 12:54

2 Answers 2

3

Try concatenating the lists of numbers, or use forvalues:

set more off

// option 1, or some variation
numlist "1/1600"
local firstlist `r(numlist)'

numlist "1601/1603"
local all `firstlist' `r(numlist)'

foreach i of local all {
   display `i'
}

// option 2
forvalues i = 1/1603 {
   display `i'
}

forvalues is documented as being faster, so use that, if you can.

There is a limit for "# of characters in a macro", depending on the Stata flavor, as documented in help limits:

8,681
165,200
1,081,511

Update

This however doesn't work:

foreach i of numlist `all' {
   display `i'
}

reporting

invalid numlist has too many elements r(123);

So if the user-written command parses as numlist, you might have problems with that too. My suggestion is to try and report back.

4
  • I missed your original comment on forvalues. Just ignore, if not viable. Nov 19, 2015 at 13:34
  • I'm not sure if the macro limit applies, but if it does I don't think I am hitting it. The numlist elements are all 2 or 3 digits, with single spaces, so a numlist of 2,000 elements would only be 8,000 characters at most. Unless I am missing something? Also edited to add more info about how -synth- uses the numlist. Nov 19, 2015 at 13:53
  • Tried your concatenating suggestion, Roberto. The -synth- option (required) for control units is -counit(numlist)-. I concatenated three lists and did -counit(`all')- and received the same error: "counit() invalid -- invalid numlist has too many elements." There is an unnecessary step in the -synth- .ado file that grabs labels for the control units, and it seems to be the only place that parses as a numlist. I think it might be possible to remove that section, so I might reconfigure the ado and try that. Nov 19, 2015 at 16:11
  • Yes, as expected. Modifying the .ado file might be your way out. If you have problems with that, post another question, probably linking back to this one. Nov 19, 2015 at 20:05
0

While I couldn't find the numlist error easily in the .ado file. I am getting around this issue by selecting a subsample of donors for the synthetic control, with the number of groups equal to the limit of numlist. In my case I want to keep most of the donors that are logically in the proximity (geographically or similar population or other characteristics) of the treated unit. I subsample those first and I fill up the limit with additional units selected randomly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.