Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: [Stata 12] Issue with -export excel-
From
Eric Booth <[email protected]>
To
"<[email protected]>" <[email protected]>
Subject
Re: st: [Stata 12] Issue with -export excel-
Date
Wed, 27 Jul 2011 23:37:03 +0000
<>
Thanks Alan, this clears it up. I didn't think about "!" being seen as part of the expression in the single-line case, so when I coded something similar in the past I must have used -shell- instead of -!- (which does work in a single-line in both 11 and 12).
- Eric
On Jul 27, 2011, at 6:06 PM, Alan Riley wrote:
> Eric Booth ([email protected]) asked some questions about Stata 12.
>
> Eric's first question was about an error he received after exporting a
> dataset to .xlsx format with -export excel-. He answered his own question
> when he found that one of his string variables contained a binary character
> in one of its values. Excel cannot read a .xlsx file which contains
> a binary character in a string value. Printable extended ASCII characters
> are supported.
>
> Eric's third question regarding shifting blocks of code in the
> Do-file Editor in Stata for Mac was answered here:
>
> http://www.stata.com/statalist/archive/2011-07/msg00963.html
>
> Eric's second question involved an error he received when using
> an -if- statement without curly braces { } to indicate the code
> that should be executed when the -if- condition is true. In
> addition, the code he wanted to execute used an '!' to shell
> out to the operating system.
>
> When Eric coded
>
> foreach file in input dta {
> if "`c(os)'" == "MacOSX" {
> !open "from`file'.xlsx"
> }
> }
>
> his code worked as expected. But, when he coded
>
> foreach file in input dta {
> if "`c(os)'" == "MacOSX" !open "from`file'.xlsx"
> }
>
> he received an error. Eric thought this error was new to Stata 12
> and that Stata 11 ran such code fine.
>
> Both Stata 11 and Stata 12 can execute code that looks like
>
> if some_expression do_this_if_some_expression_is_true
>
> And, both Stata 11 and Stata 12 can execute code that looks like
>
> if some_expression {
> do_this_if_some_expression_is_true
> }
>
> However, if the single-line case, if the code to be executed when the
> expression is true begins with an exclamation point (!) to shell out to
> the operating system, both Stata 11 and Stata 12 will error out:
>
> if some_expression !do_this_by_shelling_out
>
> Stata's expression parser is interpreting the '!' as part of
> the expression even though it doesn't affect evaluation of the
> expression. Thus, when shelling out to the operating system
> in an -if- condition, Eric should always code
>
> if some_expression {
> !do_this_by_shelling_out
> }
>
>
> --
> Alan
> [email protected]
>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/