         ]
       }
       {
-        begin: '\\$'
+        begin: '\\$(?=[\\w&&[^0-9]])'
         beginCaptures:
           0: name: 'punctuation.definition.string.begin.stata'
         end: '(?!\\w)'
-        endCaptures:
-          1: name: 'punctuation.definition.string.end.stata'
         patterns: [
           {include: '#macro-local'}
           {include: '#macro-global'}

  'macro-global-escaped':
    patterns: [
      {
        begin: '(\\\\\\$)(\\\\\\{)?'
        beginCaptures:
          0: name: 'punctuation.definition.string.begin.stata'
        end: '(\\\\\\})|(?=\\"|\\s|\\n|/|,)'
        endCaptures:
          1: name: 'punctuation.definition.string.end.stata'
        patterns: [
          {include: '#macro-local'}
          {include: '#macro-global'}

          }
        ]
      }
      {
        begin: '(\\\\\\$)(?=[\\w&&[^0-9]])'
        beginCaptures:
          1: name: 'punctuation.definition.string.begin.stata'
        end: '(?!\\w)'
        patterns: [
          {include: '#macro-local'}
          {include: '#macro-global'}
          {
            match: '[\\w&&[^0-9_]]\\w{0,31}|_\\w{1,31}'
            name: 'entity.name.type.class.stata'
          }
        ]
      }
    ]
  'macro-global':
    patterns: [
      {
        begin: '\\$\\{'
        beginCaptures:
          0: name: 'punctuation.definition.string.begin.stata'
        end: '\\}'
