Announcement

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

  • How to deal with the variables' names with space?

    Hi all,

    I am the beginner in STATA.

    I find that variables' name are shown in STATA with space.

    For example, one of the variable' names is "product name".

    But I could not key with any command in STATA for variable' names whose include space.

    So, how could I deal with this problem.

    For example, change "product name" to "product".

    Thanks

    Shawn

  • #2
    It sounds like you have some kind of corrupted data set. No Stata commands will produce a variable whose name contains a space, and, as you have already noticed, you cannot write commands to use such a variable name either. Where did this data set come from? How was it created?

    I suppose another possibility is that the blank space in the name is not actually a blank space but is some kind of non-printing or Unicode character that is somehow being displayed as a blank space for lack of a proper way to display it. Here's a thought. Copy the full name of the variable, including the blank, from the Variables window. Then clear Stata and paste it into the first variable of the first observation in the Data Editor, thereby creating a new variable, var1. Then run:

    Code:
    charlist var1
    return list
    The output of return list will show you, among other things, the ASCII codes of all the characters in the variable name. The ASCII code for a genuine blank space is 32. If you see some character that is not a letter, number, underscore, or ASCII 32, then what you are actually seeing is some non-printing character (that still shouldn't be legal, unless we're in Unicode here). But that might at least give you a bit of a handle on the problem.

    Comment


    • #3
      in addition to Clyde's advice, I wonder whether you are confusing the name of the variable with it's label; please show, in CODE blocks (see the FAQ), the command and the result of
      Code:
      d product*

      Comment


      • #4
        I presume this is a WITS-downloaded .dta, because I've encountered a similar issue (space in the variable names) with the downloaded .dta.
        To overcome this, first I renamed the variables then I labelled them accordingly like the following:


        Code:
        /* renaming variables */
        
        ren Selected selectednomen
        ren Native nativenomen
        ren Reporter reportercode
        ren Reporter reportername
        ren Product hscode
        ren Product hsdesc
        ren Partner partnercode
        ren Partner partnername
        ren Tariff year
        ren DutyType dutytype
        ren Simple simpleavg
        ren Weighted weightedavg
        ren Nbr totlines
        ren Imports mv
        ren Binding coverage
        
        /* labelling variables */
        
        la var selectednomen "(default) HS Combined"
        la var nativenomen "H0 = 1988, H1 = 1996, H2 = 2002, H3 = 2007, H4 = 2012"
        la var reportercode "3-digit importing country codes by WITS"
        la var reportername "importing country names"
        la var hscode "HS 6-digit level"
        la var hsdesc "product description of hscode"
        la var partnercode "3-digit exporting country codes by WITS"
        la var partnername "exporting country names"
        la var year "tariff year"
        la var dutytype "MFN = applied MFN, AHS = effective rate"
        la var simpleavg "simple average tariff of included 6-digit lines"
        la var weightedavg "average of tariffs weighted by their corresponding trade value"
        la var totlines "number of tariffs at the tariff line level"
        la var mv "import value in 1,000 USD"
        la var coverage "number of bound lines divided by the total number of lines"
        although in some circumstances the renaming doesn't work, I hope this helps pretty much.
        Last edited by Abigail Ho; 18 Jan 2018, 02:59.

        Comment

        Working...
        X