Announcement

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

  • Removing line spaces from string cell values.

    Hello fellow Stata users!

    My issue is probably a fairly easy one, yet I can't get pass it. I imported data from excel in Stata and despite the data at the data editor appears okay, when I try referring to it by the string value name the value name cannot be found. This is probably because there is an empty line in the excel cells that's passed to Stata editor. I have tried to get rid of this space line using subinstr , yet I can't get over this.

    Can someone help me get pass this?


    Thank you,
    George

  • #2
    When you say "referring to it by the string value name the value name cannot be found," I'm guessing you might mean that when you refer to the name of the string variable, Stata reports that that variable cannot be found. (Your Stata terminology is non-standard, which makes me uncertain about my interpretation.) If my understanding of what you wrote is correct, one possibility is that somehow there are non-printing characters embedded in the name of your string variable. (I don't know how that might happen, but it's the only thing I can think of that might account for the data looking OK in the data editor but Stata not recognizing a variable name.) You might test that theory by referring to the variable name in question using the "wild card" asterisk. So, if you had a variable that looked in the data editor or elsewhere like "this_variable" you might try:
    Code:
    describe *this*
    and see if Stata recognizes the variable. If so, you could use a similar trick:
    Code:
    rename *this* new_name
    If this is a misguided interpretation of what you mean, or is otherwise not helpful, I'd advise you to show us a sample of your data, a norm of Stata List described in the FAQ for new members, and also to show us exactly what command you typed and exactly how Stata responded so as to indicate "the value name cannot be found."

    Your description of "empty line in the excel cells that's passed to Stata editor" sounds like you mean something entirely different, perhaps a linefeed inserted in the middle of the contents (not the name) of a variable, which would be a different issue, but I'll leave that aside for now.
    Last edited by Mike Lacy; 22 Dec 2022, 09:36.

    Comment


    • #3
      Hello Mike and thanks for your response!

      Sorry if I made my post not clear I tried now to follow the forum's manual. My issue is not the string variable name but the values of the string variable that seem to be missing, despite in the data editor they look fine. Below using the dataex you can see that the cells appear empty despite visually in the data editor the values appear just fine (i am attaching a .png file to illustrate how the values appear). Is there something I can do to fix this?


      Thanks again.

      George


      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str12 ProcedureId1 str15(ProcedureId2 new_ProcedureId3 ProcedureId4 ProcedureId5 ProcedureId6 ProcedureId7 ProcedureId8 ProcedureId9 ProcedureId10 ProcedureId11 ProcedureId12 ProcedureId13 ProcedureId14)
      "67.12"  "
      67.2"  ""       "" "" "" "" "" "" "" "" "" "" ""
      ""       ""         ""       "" "" "" "" "" "" "" "" "" "" ""
      "68.29"  "
      74.4"   ""       "" "" "" "" "" "" "" "" "" "" ""
      "74.4"   ""         ""       "" "" "" "" "" "" "" "" "" "" ""
      "99.041" "
      99.07" "
      74.4" "" "" "" "" "" "" "" "" "" "" ""
      end
      Click image for larger version

Name:	DATA EDITOR VISUALISATION.png
Views:	1
Size:	41.3 KB
ID:	1694629

      Last edited by George Yiallouros; 23 Dec 2022, 00:23.

      Comment

      Working...
      X