»  Home »  Resources & support »  FAQs »  Option limit

Is there any way to get around the option limit in Stata’s syntax command?

Title   Option limit
Author Douglas Stave, Fargo Home Mortgage, MO, USA; modified by StataCorp

In Stata 15 and later, the option limit is 256 options. In Stata 14 and earlier, the limit was 70 options. The advice below applies whether you need to exceed either the 256-option limit or the 70-option limit.

Here is something that would fail under a 70-option limit:

 program lots_of_options
     syntax [, opt1 opt2 opt3 opt4 opt5 opt6 opt7 opt8 opt9 opt10 opt11   ///
 opt12 opt13 opt14 opt15 opt16 opt17 opt18 opt19 opt20 opt21 opt22 opt23  ///
 opt24 opt25 opt26 opt27 opt28 opt29 opt30 opt31 opt32 opt33 opt34 opt35  ///
 opt36 opt37 opt38 opt39 opt40 opt41 opt42 opt43 opt44 opt45 opt46 opt47  /// 
 opt48 opt49 opt50 opt51 opt52 opt53 opt54 opt55 opt56 opt57 opt58 opt59  ///
 opt60 opt61 opt62 opt63 opt64 opt65 opt66 opt67 opt68 opt69 opt70 opt71]
     macro list
 end

 . sysuse auto
 (1978 automobile data)

 . lots_of_options, opt1 opt50 opt71
 invalid syntax
 r(197);

You can use the * option and the ability to reset local macro 0 to cascade multiple commands to get around the 70-option limit of syntax. Note that you will have to save the standard part of your command to your own local macros before reparsing macro 0. This example shows how to allow a varlist.

 program lots_of_options
     syntax [varlist]                                                      ///
 [, opt1 opt2 opt3 opt4 opt5 opt6 opt7 opt8 opt9 opt10 opt11               ///
 opt12 opt13 opt14 opt15 opt16 opt17 opt18 opt19 opt20 opt21 opt22 opt23   ///
 opt24 opt25 opt26 opt27 opt28 opt29 opt30 opt31 opt32 opt33 opt34 opt35   ///
 opt36 opt37 opt38 opt39 opt40 opt41 opt42 opt43 opt44 opt45 opt46 opt47   ///
 opt48 opt49 opt50 opt51 opt52 opt53 opt54 opt55 opt56 opt57 opt58 opt59   ///
 opt60 opt61 opt62 opt63 opt64 opt65 opt66 opt67 opt68 opt69 *]
     local myvarlist `"`varlist'"'
     local 0 `", `options'"'
     syntax [, opt70 opt71]
         local varlist `"`myvarlist'"'
     macro list
 end

 . lots_of_options mpg weight, opt1 opt50 opt71
 S_MACH:         PC
 S_OS:           Windows
 S_FLAVOR:       Intercooled
 S_StataSE:      SE
 S_level:        95
 S_ADO:          BASE;SITE;.;PERSONAL;PLUS;OLDPLACE 
 _varlist:       mpg weight
 _opt71:         opt71
 _0:             , opt71
 _myvarlist:     mpg weight
 _opt50:         opt50
 _opt1:          opt1
 _5:             opt71
 _4:             opt50
 _3:             opt1
 _2:             weight,
 _1:             mpg

This method can be replicated to allow any number of options.

 program lots_of_options
     syntax [, opt1 opt2 opt3 opt4 opt5 opt6 opt7 opt8 opt9 opt10 opt11   ///
 opt12 opt13 opt14 opt15 opt16 opt17 opt18 opt19 opt20 opt21 opt22 opt23  ///
 opt24 opt25 opt26 opt27 opt28 opt29 opt30 opt31 opt32 opt33 opt34 opt35  ///
 opt36 opt37 opt38 opt39 opt40 opt41 opt42 opt43 opt44 opt45 opt46 opt47  ///
 opt48 opt49 opt50 opt51 opt52 opt53 opt54 opt55 opt56 opt57 opt58 opt59  ///
 opt60 opt61 opt62 opt63 opt64 opt65 opt66 opt67 opt68 opt69 *]
     local myvarlist `"`varlist'"'
     local 0 `", `options'"'
     syntax [, opt70 opt71 opt72 opt73 opt74 opt75 opt76 opt77 opt78      ///
 opt79 opt80 opt81 opt82 opt83 opt84 opt85 opt86 opt87 opt88 opt89 opt90  ///
 opt91 opt92 opt93 opt94 opt95 opt96 opt97 opt98 opt99 opt100 opt101      ///
 opt102 opt103 opt104 opt105 opt106 opt107 opt108 opt109 opt110 opt111    ///
 opt112 opt113 opt114 opt115 opt116 opt117 opt118 opt119 opt120 opt121    ///
 opt122 opt123 opt124 opt125 opt126 opt127 opt128 opt129 opt130 opt131    ///
 opt132 opt133 opt134 opt135 opt136 opt137 opt138 *]
     local 0 `", `options'"'
     syntax [, opt139 opt140 opt141 opt142 opt143 opt144 opt145 opt146    ///
 opt147 opt148 opt149 opt150 opt151 opt152 opt153 opt154 opt155 opt156    ///
 opt157 opt158 opt159 opt160 opt161 opt162 opt163 opt164 opt165 opt166    /// 
 opt167 opt168 opt169 opt170 opt171 opt172 opt173 opt174 opt175 opt176    ///
 opt177 opt178 opt179 opt180 opt181 opt182 opt183 opt184 opt185 opt186    ///
 opt187 opt188 opt189 opt190 opt191 opt192 opt193 opt194 opt195 opt196    ///
 opt197 opt198 opt199 opt200 opt201 opt202 opt203 opt204 opt205 opt206    ///
 opt207]
     local myvarlist `"`varlist'"'
     macro list
 end

 . lots_of_options, opt1 opt50 opt71 opt124 opt138 opt180 opt207
 S_MACH:         PC
 S_OS:           Windows
 S_FLAVOR:       Intercooled
 S_StataSE:      SE
 S_level:        95
 S_ADO:          BASE;SITE;.;PERSONAL;PLUS;OLDPLACE        
 _varlist:       mpg weight
 _opt207:        opt207
 _opt180:        opt180
 _0:             , opt180 opt207
 _myvarlist:     mpg weight
 _opt138:        opt138
 _opt124:        opt124
 _opt71:         opt71
 _opt50:         opt50
 _opt1:          opt1
 _9:             opt207
 _8:             opt180
 _7:             opt138
 _6:             opt124
 _5:             opt71
 _4:             opt50
 _3:             opt1
 _2:             weight,
 _1:             mpg

This method still catches any option that does not exist.

 . lots_of_options, opt1 opt50 opt71 opt124 opt138 opt180 opt207 opt208
 option opt208 not allowed
 r(198);
    
 . lots_of_options, opt1 opt50 opt71 opt124 opt138 opt180 opt207 otheropt
 option otheropt not allowed
 r(198);

Stata

Shop

Support

Company


The Stata Blog: Not Elsewhere Classified Find us on Facebook Follow us on Twitter LinkedIn YouTube Instagram
© Copyright 1996–2020 StataCorp LLC   •   Terms of use   •   Privacy   •   Contact us