Announcement

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

  • Question about generate an indicator variable with inlist.

    Hi all,

    When I used my code to generate an indicator variable, Stata told me "expression too long", any other advanced coding can solve this issue?

    Thanks.

    My code

    Code:
        bys beneid tcn: gen byte wellchild15 = 1 if inlist(cpt,"94467", "99865", "93568", "99381", "99382", ///
        "99383", "99384", "99385", "99391", "99392", "99393", "99394", "99395", "99461")

  • #2
    Asked about a half hour ago and answered a few minutes ago at https://www.statalist.org/forums/for...e-new-variable.

    Bumping is discouraged. Certainly after only a half hour it is not appropriate.

    By the way, I strongly recommend against the -gen var = 1 if logical_expression- approach, as it creates a variable that is coded 1 for true and missing value for false. That kind of variable does not work well in Stata, and is likely to lead to confusion and errors when you use it. It is much better to code the variable 1 for true and 0 for false. So a better approach is -gen var = logical_expression-, which will automatically create the 0/1 coding.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      Asked about a half hour ago and answered a few minutes ago at https://www.statalist.org/forums/for...e-new-variable.

      Bumping is discouraged. Certainly after only a half hour it is not appropriate.

      By the way, I strongly recommend against the -gen var = 1 if logical_expression- approach, as it creates a variable that is coded 1 for true and missing value for false. That kind of variable does not work well in Stata, and is likely to lead to confusion and errors when you use it. It is much better to code the variable 1 for true and 0 for false. So a better approach is -gen var = logical_expression-, which will automatically create the 0/1 coding.
      Perfect, thanks for your suggestion.

      Comment

      Working...
      X