Announcement

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

  • define a new directory with "local" command

    Hi everybody,
    I am a new (french) user of Stata software.
    I know it is possible to cut short some pathway for open a data file but I struggle to manage it.
    Someone can help me? I use Stata 11


    I did :

    clear
    local pathdata "C:\Users\Documents\data"
    use `pathdata'\ch.dta
    => But the data file didn't open
    Stata said to me "file \ch.dta not found"


    On the other hand, when I write down
    use "C:\Users\Documents\data\ch.dta"
    => my data file called ch open

    Thank you for you help


  • #2
    A potential problem with using macros in file paths is that the backslash is also used as an escape character that prevents Stata from evaluating local macros. The solution is to use forward slashes. For more see: http://www.stata-journal.com/sjpdf.h...iclenum=pr0042

    However, I don't think that that is the problem here. Instead I suspect that you have this in a .do file and ran that do file line by line. A local macro is local, so it exist as long as a section of a .do file is run and is gone as soon as Stata stops running that section of the .do file. The solution is to run at least the local definition and its use together. Better yet, just make sure you can run your entire do file in one go and do that.
    Last edited by Maarten Buis; 04 Aug 2015, 05:37.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Maarten gave you very good advice on using macros in file paths. I also recommend to change the working directory once and then use files without the full path. Type help cdfor more information.
      The problem with your syntax is the quotation marks:
      clear
      local pathdata "C:\Users\Documents\data"
      use "`pathdata'\ch.dta"

      Comment


      • #4
        Thank you both of you!
        Actually Maarten was right.
        Before I ran
        local pathdata "C:\Users\Documents\data"
        and then
        use `pathdata'\ch.dta

        Now I run the both command together and It perfectly work!

        I'm happy to be part of this forum. I think I will use it often
        See you later
        Flavie

        Comment

        Working...
        X