<Comment>/* Test file for kate's stata syntax highlighting</Comment><br/>
<Comment>*/</Comment><br/>
<Normal Text>*! </Normal Text><Mata>version</Mata><Normal Text> 1.2.0 2mar2003 E. Leuven</Normal Text><br/>
<Keyword>program</Keyword><Normal Text> </Normal Text><Keyword>define</Keyword><Normal Text> spellsplit</Normal Text><br/>
<Normal Text>        </Normal Text><Mata>version</Mata><Normal Text> 7</Normal Text><br/>
<Normal Text>        </Normal Text><Keyword>syntax</Keyword><Normal Text> [anything], spell(</Normal Text><Keyword>varlist</Keyword><Normal Text> </Normal Text><Functions>min</Functions><Normal Text>=2 </Normal Text><Functions>max</Functions><Normal Text>=2) [ </Normal Text><Keyword>by</Keyword><Normal Text>(</Normal Text><Keyword>varlist</Keyword><Normal Text>)]</Normal Text><br/>
<Normal Text>        </Normal Text><Keyword>tokenize</Keyword><Normal Text> </Normal Text><Macro>`spell'</Macro><br/>
<Normal Text>        </Normal Text><Keyword>local</Keyword><Normal Text> date0 </Normal Text><Macro>`1'</Macro><br/>
<Normal Text>        </Normal Text><Keyword>local</Keyword><Normal Text> date1 </Normal Text><Macro>`2'</Macro><br/>
<Normal Text>        </Normal Text><Keyword>local</Keyword><Normal Text> f0 : </Normal Text><Keyword>format</Keyword><Normal Text> </Normal Text><Macro>`date0'</Macro><br/>
<Normal Text>        </Normal Text><Keyword>local</Keyword><Normal Text> f1 : </Normal Text><Keyword>format</Keyword><Normal Text> </Normal Text><Macro>`date1'</Macro><br/>
<Normal Text></Normal Text><br/>
<Normal Text>        </Normal Text><Comment>/* set default statistic */</Comment><br/>
<Normal Text>        </Normal Text><Keyword>local</Keyword><Normal Text> current </Normal Text><String>"mean"</String><br/>
<Normal Text></Normal Text><br/>
<Normal Text>        gettoken left anything : anything, </Normal Text><Functions>match</Functions><Normal Text>(prns)</Normal Text><br/>
<Normal Text>        </Normal Text><Keyword>while</Keyword><Normal Text> </Normal Text><String>"`left'"</String><Normal Text>!=</Normal Text><String>""</String><Normal Text> {</Normal Text><br/>
<Normal Text>                </Normal Text><Keyword>if</Keyword><Normal Text> </Normal Text><String>"`prns'"</String><Normal Text>!=</Normal Text><String>""</String><Normal Text> {</Normal Text><br/>
<Normal Text>                        </Normal Text><Keyword>if</Keyword><Normal Text> !</Normal Text><Functions>inlist</Functions><Normal Text>(</Normal Text><String>"`left'"</String><Normal Text>,</Normal Text><String>"mean"</String><Normal Text>,</Normal Text><String>"sum"</String><Normal Text>) {</Normal Text><br/>
<Normal Text>                                </Normal Text><Keyword>di</Keyword><Normal Text> </Normal Text><Keyword>as</Keyword><Normal Text> </Normal Text><Keyword>error</Keyword><Normal Text> </Normal Text><String>"Statistic `left' not supported"</String><br/>
<Normal Text>                                </Normal Text><Keyword>exit</Keyword><Normal Text> 198</Normal Text><br/>
<Normal Text>                        }</Normal Text><br/>
<Normal Text>                        </Normal Text><Keyword>local</Keyword><Normal Text> current </Normal Text><String>"`left'"</String><br/>
<Normal Text>                }</Normal Text><br/>
<Normal Text>                </Normal Text><Keyword>else</Keyword><Normal Text> {</Normal Text><br/>
<Normal Text>                        </Normal Text><Keyword>local</Keyword><Normal Text> </Normal Text><Macro>`current'</Macro><Normal Text>vars  </Normal Text><Macro>``current'</Macro><Normal Text>vars' </Normal Text><Macro>`left'</Macro><br/>
<Normal Text>                }</Normal Text><br/>
<Normal Text>                gettoken left anything : anything, </Normal Text><Functions>match</Functions><Normal Text>(prns)</Normal Text><br/>
<Normal Text>        }</Normal Text><br/>
<Normal Text>        </Normal Text><Keyword>if</Keyword><Normal Text> (</Normal Text><String>"`meanvars'"</String><Normal Text>!=</Normal Text><String>""</String><Normal Text>) {</Normal Text><br/>
<Normal Text>                </Normal Text><Keyword>confirm</Keyword><Normal Text> </Normal Text><Keyword>var</Keyword><Normal Text> </Normal Text><Macro>`meanvars'</Macro><br/>
<Normal Text>                </Normal Text><Keyword>unab</Keyword><Normal Text> meanvars : </Normal Text><Macro>`meanvars'</Macro><br/>
<Normal Text>        }</Normal Text><br/>
<Normal Text>        </Normal Text><Keyword>if</Keyword><Normal Text> (</Normal Text><String>"`sumvars'"</String><Normal Text>!=</Normal Text><String>""</String><Normal Text>) {</Normal Text><br/>
<Normal Text>                </Normal Text><Keyword>confirm</Keyword><Normal Text> </Normal Text><Keyword>var</Keyword><Normal Text> </Normal Text><Macro>`sumvars'</Macro><br/>
<Normal Text>                </Normal Text><Keyword>unab</Keyword><Normal Text> sumvars : </Normal Text><Macro>`sumvars'</Macro><br/>
<Normal Text>        }</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Normal Text>        </Normal Text><Keyword>quietly</Keyword><Normal Text> {</Normal Text><br/>
<Normal Text>                g _count = 1</Normal Text><br/>
<Normal Text>                </Normal Text><Keyword>local</Keyword><Normal Text> xvars </Normal Text><Macro>`meanvars'</Macro><Normal Text> </Normal Text><Macro>`sumvars'</Macro><Normal Text> _count</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Normal Text>                </Normal Text><Comment>/* create dummy by-var if no by option is specified */</Comment><br/>
<Normal Text>                </Normal Text><Keyword>if</Keyword><Normal Text> </Normal Text><String>"`by'"</String><Normal Text>==</Normal Text><String>""</String><Normal Text> {</Normal Text><br/>
<Normal Text>                        </Normal Text><Keyword>tempvar</Keyword><Normal Text> </Normal Text><Keyword>by</Keyword><br/>
<Normal Text>                        g </Normal Text><Keyword>byte</Keyword><Normal Text> </Normal Text><Macro>`by'</Macro><Normal Text> = 1</Normal Text><br/>
<Normal Text>                }</Normal Text><br/>
<Normal Text>                </Normal Text><Keyword>tempvar</Keyword><Normal Text> </Normal Text><Macro>`xvars'</Macro><Normal Text> </Normal Text><Macro>`by'</Macro><br/>
<Normal Text></Normal Text><br/>
<Normal Text>                </Normal Text><Comment>/* create negative for subtraction when spell ends */</Comment><br/>
<Normal Text>                cap </Normal Text><Keyword>foreach</Keyword><Normal Text> v </Normal Text><Keyword>of</Keyword><Normal Text> </Normal Text><Keyword>varlist</Keyword><Normal Text> </Normal Text><Macro>`xvars'</Macro><Normal Text> {</Normal Text><br/>
<Normal Text>                        g </Normal Text><Keyword>double</Keyword><Normal Text> </Normal Text><Macro>``v'</Macro><Normal Text>' = -</Normal Text><Macro>`v'</Macro><br/>
<Normal Text>                        </Normal Text><Keyword>local</Keyword><Normal Text> txvars </Normal Text><Macro>`txvars'</Macro><Normal Text> </Normal Text><Macro>``v'</Macro><Normal Text>'</Normal Text><br/>
<Normal Text>                }</Normal Text><br/>
<Normal Text>                cap </Normal Text><Keyword>foreach</Keyword><Normal Text> v </Normal Text><Keyword>of</Keyword><Normal Text> </Normal Text><Keyword>varlist</Keyword><Normal Text> </Normal Text><Macro>`by'</Macro><Normal Text> {</Normal Text><br/>
<Normal Text>                        g </Normal Text><Keyword>double</Keyword><Normal Text> </Normal Text><Macro>``v'</Macro><Normal Text>' = </Normal Text><Macro>`v'</Macro><br/>
<Normal Text>                        </Normal Text><Keyword>local</Keyword><Normal Text> txvars </Normal Text><Macro>`txvars'</Macro><Normal Text> </Normal Text><Macro>``v'</Macro><Normal Text>'</Normal Text><br/>
<Normal Text>                }</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Normal Text>                </Normal Text><Keyword>stack</Keyword><Normal Text> </Normal Text><Macro>`date0'</Macro><Normal Text> </Normal Text><Macro>`xvars'</Macro><Normal Text> </Normal Text><Macro>`by'</Macro><Normal Text> </Normal Text><Macro>`date1'</Macro><Normal Text> </Normal Text><Macro>`txvars'</Macro><Normal Text>, into(</Normal Text><Macro>`date0'</Macro><Normal Text> </Normal Text><Macro>`xvars'</Macro><Normal Text> </Normal Text><Macro>`by'</Macro><Normal Text>) </Normal Text><Keyword>clear</Keyword><br/>
<Normal Text></Normal Text><br/>
<Normal Text>                </Normal Text><Comment>/* calculate totals per date */</Comment><br/>
<Normal Text>                cap </Normal Text><Keyword>foreach</Keyword><Normal Text> v </Normal Text><Keyword>of</Keyword><Normal Text> </Normal Text><Keyword>varlist</Keyword><Normal Text> </Normal Text><Macro>`xvars'</Macro><Normal Text> {</Normal Text><br/>
<Normal Text>                        </Normal Text><Keyword>egen</Keyword><Normal Text> </Normal Text><Keyword>double</Keyword><Normal Text> </Normal Text><Macro>``v'</Macro><Normal Text>' = </Normal Text><Keyword>sum</Keyword><Normal Text>(</Normal Text><Macro>`v'</Macro><Normal Text>), </Normal Text><Keyword>by</Keyword><Normal Text>(</Normal Text><Macro>`by'</Macro><Normal Text> </Normal Text><Macro>`date0'</Macro><Normal Text>)</Normal Text><br/>
<Normal Text>                }</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Normal Text>                </Normal Text><Comment>/* unique dates only */</Comment><br/>
<Normal Text>                </Normal Text><Keyword>by</Keyword><Normal Text> </Normal Text><Macro>`by'</Macro><Normal Text> </Normal Text><Macro>`date0'</Macro><Normal Text>, </Normal Text><Keyword>sort</Keyword><Normal Text>: </Normal Text><Keyword>keep</Keyword><Normal Text> </Normal Text><Keyword>if</Keyword><Normal Text> </Normal Text><Constants>_n</Constants><Normal Text>==1</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Normal Text>                </Normal Text><Comment>/* calculate totals (+ when spell starts - when ends) */</Comment><br/>
<Normal Text>                </Normal Text><Keyword>sort</Keyword><Normal Text> </Normal Text><Macro>`by'</Macro><br/>
<Normal Text>                cap </Normal Text><Keyword>foreach</Keyword><Normal Text> v </Normal Text><Keyword>of</Keyword><Normal Text> </Normal Text><Keyword>varlist</Keyword><Normal Text> </Normal Text><Macro>`xvars'</Macro><Normal Text> {</Normal Text><br/>
<Normal Text>                        </Normal Text><Keyword>by</Keyword><Normal Text> </Normal Text><Macro>`by'</Macro><Normal Text>: </Normal Text><Keyword>replace</Keyword><Normal Text> </Normal Text><Macro>`v'</Macro><Normal Text> = </Normal Text><Keyword>sum</Keyword><Normal Text>(</Normal Text><Macro>``v'</Macro><Normal Text>')</Normal Text><br/>
<Normal Text>                }</Normal Text><br/>
<Normal Text>                </Normal Text><Keyword>by</Keyword><Normal Text> </Normal Text><Macro>`by'</Macro><Normal Text>: g </Normal Text><Macro>`date1'</Macro><Normal Text> = </Normal Text><Macro>`date0'</Macro><Normal Text>[</Normal Text><Constants>_n</Constants><Normal Text> + 1]</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Normal Text>                </Normal Text><Keyword>drop</Keyword><Normal Text> </Normal Text><Keyword>if</Keyword><Normal Text> </Normal Text><Macro>`date0'</Macro><Normal Text>></Normal Text><Macro>`date1'</Macro><br/>
<Normal Text>                </Normal Text><Keyword>drop</Keyword><Normal Text> _stack</Normal Text><br/>
<Normal Text>                </Normal Text><Keyword>drop</Keyword><Normal Text> </Normal Text><Keyword>if</Keyword><Normal Text> _count==0</Normal Text><br/>
<Normal Text>                </Normal Text><Keyword>order</Keyword><Normal Text> </Normal Text><Macro>`by'</Macro><Normal Text> </Normal Text><Macro>`date0'</Macro><Normal Text> </Normal Text><Macro>`date1'</Macro><Normal Text> </Normal Text><Macro>`xvars'</Macro><br/>
<Normal Text>                </Normal Text><Keyword>format</Keyword><Normal Text> </Normal Text><Macro>`date0'</Macro><Normal Text> </Normal Text><Macro>`f0'</Macro><br/>
<Normal Text>                </Normal Text><Keyword>format</Keyword><Normal Text> </Normal Text><Macro>`date1'</Macro><Normal Text> </Normal Text><Macro>`f1'</Macro><br/>
<Normal Text></Normal Text><br/>
<Normal Text>                cap </Normal Text><Keyword>for</Keyword><Normal Text> </Normal Text><Keyword>var</Keyword><Normal Text> </Normal Text><Macro>`meanvars'</Macro><Normal Text>: </Normal Text><Keyword>replace</Keyword><Normal Text> X = X/_count</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Normal Text>                </Normal Text><Keyword>compress</Keyword><br/>
<Normal Text>        }</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Keyword>end</Keyword><br/>
