Announcement

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

  • Fixing a tab / unusual empty spacing in stata.

    Hello Stata users,

    I am running into a problem where string observations under the 'browse window' only show part of what is technically in the cell.

    As an example:

    A string observation will have a name "Bobby Smith" in a cell, but if I hit the data editor, click on that cell, and press > after the h in Smith, it will jump to another word, which is technically in the cell, but "hidden" with the browse window. I've copied and pasted the browse window into excel and there is clearly something funky going on inside the cell (where excel will place the word past 'Smith >" into another cell).

    I would like to remove this odd spacing inside stata, and add a regular space, so I can clearly see what is going on with these nasty observations.

    I've tried a few of the trimming commands (strtrim, etc, but these don't seem to be doing the trick).

    I hope this makes sense.
    Thank you in advance for your help!

  • #2
    Trimming refers to spaces, only.

    Try replacing tabs with spaces:

    Code:
     
    . clonevar mycopy = mystr 
    . replace mycopy = subinstr(mycopy, "`=char(9)'", " ", .)
    Should work for Stata < 14. Not tested with 14.

    Comment


    • #3
      That works in 14. As the tab is char(9), the change to support Unicode does not bite.

      Code:
      . set obs 1
      number of observations (_N) was 0, now 1
      
      . gen text = "frog" + char(9) + "toad" + char(9) + "newt"
      
      . l
      
           +----------------+
           |           text |
           |----------------|
        1. | frog     toad    newt |
           +----------------+
      
      . gen text2 = itrim(text)
      
      . l
      
           +---------------------------------+
           |           text            text2 |
           |---------------------------------|
        1. | frog     toad    newt   frog     toad    newt |
           +---------------------------------+
      
      . replace text2 = subinstr(text2, char(9), " ", .)
      (1 real change made)
      
      . l
      
           +---------------------------------+
           |           text            text2 |
           |---------------------------------|
        1. | frog     toad    newt   frog toad newt |
           +---------------------------------+
      Like my previous post, the presumption here is that tabs are the problematic character. If it's some other character, the solution suggested is similar: identify the character and replace it with spaces.

      Comment


      • #4
        Thank you so much Nick Cox! Had to use char(9), char(10) and char(13) to fix all my problems. Phew!

        Now the data looks good as new!

        Comment

        Working...
        X