Announcement

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

  • Error when using egen command with dashed keywords

    When using the egen command for searching (and making a variabe based on) dashed keywords like 'data-driven' the following error sign pops up: - invalid name r(198);

    Am I able to search for words with a dash in between? And how does it work?

  • #2
    I can't visualize what you're trying. Please give a data example and show a real or realistic example of the code you're using. https://www.statalist.org/forums/help#stata explains.

    Comment


    • #3
      Example:

      I use variable W1 (Website1) as string data (text descriptions) and use the following command to create a new string variable based on the wordcount: egen X_noccur_W1 = noccur(Website1), string("X").

      This command works and creates a new variable (string): egen digitally_noccur_W1 = noccur(Website1), string("digitally")
      This command does not work: egen data-driven_noccur_W2 = noccur(Website2), string("data-driven") - invalid name r(198);




      Is there any solution for the problem that words with a dash cannot be used?

      Comment


      • #4
        The error is that a dash is not a valid character in a variable name (what immediately follows -egen-). Remove the dash and it should work.
        Last edited by Leonardo Guizzetti; 14 Apr 2022, 07:26.

        Comment


        • #5
          Leonardo Guizzetti is correct here. The error has nothing to do with searching for keywords with dashes except that you asked for a variable name that isn't allowed.

          Beyond that, the egen function noccur() is community-contributed from egenmore on SSC, as you are asked to explain. The link in #2 applies once more.

          This function is dispensable. If you want to count occurrences of a string, the device explained at https://www.stata-journal.com/articl...article=dm0056 is often a better idea.

          If the problem is to check for occurrence of substrings, use strpos(), strmatch() or a regular expression function.

          Comment


          • #6
            Thank you!

            Comment

            Working...
            X