Announcement

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

  • Error message: "Cannot generate new variables using stub"

    There seems to be little guidance online regarding this error message.
    In essence, I want to generate new variables from multiple response variables from a survey. I found guidance that the error message may be linked to a long varname. This is, however, not the complete story.
    I have the varlist aboutjournal1-aboutjournal40. These have concatenated responses (1,2,3), (1,2), (1,3), (2,3), (1), (2), (3). I want to split these into separate variables and destring.
    The following:

    The ideal code would look as follows:
    Code:
    rename aboutjournal# j# 
    split j1, parse(,) // to be repeated for each aboutjournal in a for loop.
    However: The above code gives the error message "cannot generate new variables using stub j1". Surprisingly, if I instead only use the rename function for one specific variable, aboutjournal1, the code below comes without error.
    rename aboutjournal1 j1
    split j1, parse(,)
    How can I solve this error message, and why does it appear?

  • #2
    SOLUTION: This clearly has to do with the fact that aboutjournal1 would create aboutjournal11, -12, and -13. This causes problems if aboutjournal11 already exists as a separate variable. What alternatives are there than to use multiple renames? You should use the generate(stub) option, which generates the varname accordingly. Use this code for the solution to the problem:
    foreach v of varlist aboutjournal1-aboutjournal40{
    split `v', parse(,) generate(`v'_) // generates new columns for concatenated responses
    }
    Last edited by Castor Comploj; 18 Jun 2022, 03:17.

    Comment


    • #3
      Thank you for closing the thread by posting the solution you found.

      Comment

      Working...
      X