Announcement

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

  • Variable with character

    Dear All

    I need help with a basic question that I can't find a solution to

    I have variables that contains a tilde (~) eg trans~t. The tab command or any other command won't work on it. How do I solve this issue.

    Thanks

  • #2
    Have you imported the data from some other format? Please show a reproducible example, using dataex.

    Best
    Daniel

    Comment


    • #3
      Those are abbreviated displays of variable names that are longer than your command's permitted maximum length for displaying names. Variable names aren't permitted to contain tildes; see the user manual's U [User's Guide] Section 11.3 Naming conventions.

      In order to find out the actual name, either type the first few characters (e.g., trans) and hit the tab key for Stata to display a dropdown menu with all of the variables in your dataset that begin with those same characters, or
      Code:
      describe trans*

      Comment


      • #4
        My guess matches Joseph's: the question is about variable names, not string variables with tilde characters in their values.

        Comment


        • #5
          I still think we need to see an example. If this is about variable names, the initial post suggests that something like

          Code:
          sysuse auto
          tabulate t~n
          "does not work" (whatever that means), which clearly is not the case as it works perfectly.

          Best
          Daniel

          Comment


          • #6
            This could be an illegal variable name in a dta file made by some external program.

            First, to validate the dta file to be used:
            Code:
            dtaverify filename.dta
            . Also, report you Stata version from running
            Code:
            verinst
            If an external program did use tilde in variable names (as in the example below), the dta will be read by Stata, but using the illegal names will not work.

            In the current version of Stata some commands like describe , tabulate will work with the illegal name, while others, like rename will not, so renaming the variable is impossible using the command rename.
            Code:
            . gen newvar = var~ame
            var~ame invalid name
            r(198);
            
            . rename var~ame newname
            var~ame invalid name
            To rename illegal variable names on could use mata functions refering to the index of the variable, thus not using the illegal name as argument:
            Code:
            foreach varname of varlist * {
            
                local i = `i' + 1
                
                if ( "`varname'" != ustrtoname("`varname'") ) {
            
                    mata : st_varrename(`i', ustrtoname("`varname'") )
                }
            }

            Comment


            • #7
              Originally posted by daniel klein View Post
              "does not work" (whatever that means), which clearly is not the case as it works perfectly.
              I agree that following the forum's FAQ would have helped immeasurably, but I'm guessing that the OP has three or more variables whose names begin with trans and end with t after the tabulate command., and saw something like trans~t ambiguous abbreviation. That's just a guess, of course, in the absence of any information.

              Comment


              • #8
                Dear All, thank you for your comments. Am new to stata and just discovered the variable window displays the variable in full without ~ which was showing in the browse window. Issue resolved. But i appreciate your comments

                Comment

                Working...
                X