title: Error when using string variables in the table command
body: <p>Why does Stata complain with a cryptic error when I use string variables in the <code>table</code> command?</p>
  
  <p>Consider the following toy example:</p>
  
  <pre><code>sysuse auto, clear
  decode foreign, g(foreign_str)
  table foreign, contents(n foreign_str mean mpg)
  </code></pre>
  
  <p>This raises an <code>r(111) variable __000002 not found</code> error in Stata 13.1. </p>
  
  <p>Tracing the error tells me that it is trying to run <code>format __000002 %9.0gc</code> and crashing when it does not find the variable. If I switch the order of the variables in the <code>clist</code>, that is i run <code>table foreign, contents(n mpg_rank mean mpg)</code>, I get the same error but with <code>__000003</code> instead of <code>__000002</code>. </p>
  
  <p>So it appears that Stata crashes when it finds the string variable. If I replace the string variable with a numeric variable, the error doesn't occur. </p>
  
  <p>I know it is not meaningful to compute summary statistics on string variables, but counting the number of observations of a string variable (in each group specified by the rowvar) makes perfect sense. </p>