Announcement

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

  • quotes: do file vs command line

    Greetings!

    I think I have a problem with quoting at the command line vs a do file?
    My do file contains:

    local lname _summary.csv
    local lid PF006
    import delimited "`lid'`lname’”, clear
    <lots of code>
    gen subject_id = “”
    replace subject_id =`"`lid'"'
    <more code>

    Unfortunately, the do file always returns a blank for subject_id
    In troubleshooting, I stop the do file after the ‘ gen subject_id =“” ‘ line.
    Then, when I issue the very same replace command from the command line, PF006 is correctly returned.
    I’ve tried all permutations of quoting to no avail. I’ve tried to concatenate quotes and use char(34) without luck. Can you help?

    Regards,
    -bill

    William Paredes
    Clinical Research Coordinator
    Dept of Medicine; Div of Nephrology
    Albert Einstein College of Medicine
    1300 Morris Park Avenue
    Block Bldg, Rm 612
    Bronx NY 10461
    [718] 430-3088 (office)
    [718] 430-2044 (fax)

  • #2
    Welcome to Statalist, William.

    My guess is that, with your code displayed in the Do-file Editor window, you selected the first few lines and submitted them, then selected subsequent lines, and submitted them, and so forth.

    The problem is, when you submit selected lines from the Do-file Editor, it writes them to a temporary do-file and submits that file. (You'll see that in the Results window, where your output is preceded by a do command with a meaningless name.) The local macro is defined, but once the temporary do-file ends, the local macro vanishes. So later you are effectively executing
    Code:
    gen subject_id = “”
    replace subject_id =`""'
    These two commands would result in something like the following in your Results window or log file
    Code:
    (74 missing values generated)
    (0 real changes made)
    The solution is to run the entire contents of the Do-file Editor window at the same time.

    Comment


    • #3
      Thanks for your help. You solved the mystery.
      -bill

      Comment

      Working...
      X