Announcement

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

  • Question about macro syntax in stata

    Hi everyone,

    I have a quick question. Could anyone explain me the difference between these two local macros in stata:

    Code:
    ***
    * Creation of paths and folders
    local project_dir "//hes-nas-prairie.hes.adhes.hesge.ch/Home_M/michael.duartego/Documents/Desktop/Analyse"
    cd `project_dir'
    *
    * making folders in the current directory
    local d `" "rawdata" "Figures" "tables" "do_files" "master" "'
    *
    foreach folder in `d' {
    di `"`folder'"'
    cap  mkdir `"`project_dir'/`folder'"'  
    }
    and

    Code:
    ***
    * Creation of paths and folders
    local project_dir "//hes-nas-prairie.hes.adhes.hesge.ch/Home_M/michael.duartego/Documents/Desktop/Analyse"
    cd `project_dir'
    *
    * making folders in the current directory
    local d ` rawdata Figures tables do_files master'
    *
    foreach folder in `d' {
    di `folder'
    cap  mkdir `project_dir'/`folder'  
    }
    The macro in red is not working. But I just want to understand better why I have to use double quotes in my first example, in order to create properly my folder's names.
    Thank you in advance.

    Best,
    Last edited by Michael Duarte Goncalves; 02 May 2023, 00:48. Reason: macro

  • #2
    A string is always contained in either double quotes (" ") or compound double quotes (`" "') but never in single quotes (` '). The later indicates a local macro and not a string. So the line
    local d ` rawdata Figures tables do_files master' means that the local macro d should contain the content of a local macro with the name rawdata Figures tables do_files master . Since presumably no such macro exists, the local macro d now contains an empty string.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Maarten Buis:

      Thank you very much for your answer.
      I understand now why I persisted in my mistake.

      Comment

      Working...
      X