Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generate bug

    Syntax diagram for generate allows for specification of desired variable storage type preceding the variable name.
    such as
    Code:
    generate double price=cost/volume
    A colleague of mine has just shown me the situation where the syntax was written incorrectly, but Stata didn't complain:
    Code:
    generate c str10="test"
    I initially suspected some rudimentary flexibility in the syntax, such as permitted by the format command (which allows swapping the order of the format and variable name). But it turns out that Stata completely ignores the type specification in such a case. Moreover, type can be numeric and still cause no syntax error:
    Code:
    generate d double="test"
    I think it is a syntax bug and the correct behavior should be to report an error of either "invalid type" as according to syntax c is not a Stata type, or "invalid varname" as str10 can't be a variable name because it is reserved.

    Interestingly the qualifier if can also be inserted before the equal sign, and it does work!
    Code:
    . sysuse auto
    (1978 Automobile Data)
    . generate  t if mpg>22="test"
    (48 missing values generated)
    . generate  t2 double if mpg>22="test"
    (48 missing values generated)
    Best, Sergiy Radyakin
    Last edited by Sergiy Radyakin; 15 Aug 2014, 12:31.
Working...
X