Announcement

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

  • Applying macro to local data file location

    Hi I hope this is clear enough-- I have read that I should create a new directory to be able to hide the actual file name and honestly don't understand what is meant by re-creating a new directory so I am just going to try to explain this without creating a directory.
    I am using a dataset and do files from some very advanced stata code writers at the World bank, trying to do a similar analysis on a sub-sample of their population (only young people 15-29 years old) so I am just trying to follow along the do file they provided and I'm stuck on the initial instruction below. Obviously that sample path doesn't work on my machine so I try to use the file path from my machine that worked to open the dataset to begin with but now tells me is invalid. I guess it's the file path and not the macro command I'm using ($in/...) that is the source of the problem? Please advise--see below:

    /* Depending on the country, we merged the individual respondent data with the household roster */
    * Merge Main data with Household.

    *. use $in/HH_ROSTER_s10_final.dta, replace

    file /HH_ROSTER_s10_final.dta not found
    r(601);

    So instead i used the same file path I used earlier to identify the data set: (I am trying to follow the instructions for hiding the actual file path but acknowledging I don't understand exactly how to create a new directory to accomplish this!)

    use $in/C:\Users\heather.dolphin\A123456789012345678901234 5678901234567890\B12345678901234567890123456789012 34567890\C1234567890123456789012345678901234567890 \D1234567890123456789012345678901234567890\E123456 7890123456789012345678901234567890\STEP Vietnam_HH Roster_s10_final.dta, replace
    Now I am told the command was invalid r(198) Can you help?

    I assume the individual respondent data was in fact merged with the household roster...but perhaps you have a recommendation for how I can know for sure ?
    Thanks
    Heather

  • #2
    Since you don't show the code that created global macro in, nobody can know what it contains and what your first -use- command is actually trying to do.

    The second use command is clearly problematic. Regardless of what $in contains, having C: in the middle of a pathname is going to be a problem, since C: necessarily lies at the root of the directory tree. It is also problematic because there is an embedded blank between HH and Roster. Consequently, Stata sees a request to use some file named STEPVietnam_HH that lives in some directory that cannot possibly exist, and that is followed by some meaningless characters that read Roster_s10_final.dta.So it just gives up and says that's invalid--an unhelpful but true error message. The entire pathname from start to finish, once you make it a legal path name, needs to be bound in quotes.

    Comment


    • #3
      It seems to me the problem with the first use command is that the global macro $in has not been created. It is meant to contain the name of the directory within which a file named HH_ROSTER_s10_final.dta exists.

      Looking at your second use command it seems to me you wanted
      Code:
      global in C:\Users\heather.dolphin\A1234567890123456789012345678901234567890\B12345678901234567890123456789012 34567890\C1234567890123456789012345678901234567890 \D1234567890123456789012345678901234567890\E1234567890123456789012345678901234567890
      use "$in/STEP Vietnam_HH Roster_s10_final.dta", replace
      I'm sympathetic to you as apparently a new user of Stata tyring to follow existing code written by experienced users - there is quite a lot to absorb.I'd like to encourage you to take a step back from your immediate tasks.

      When I began using Stata in a serious way, I started, as have others here, by reading my way through the Getting Started with Stata manual relevant to my setup. Chapter 18 then gives suggested further reading, much of which is in the Stata User's Guide, and I worked my way through much of that reading as well. All of these manuals are included as PDFs in the Stata installation and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

      The objective in doing the reading was not so much to master Stata - I'm still far from that goal - as to be sure I'd become familiar with a wide variety of important basic techniques, so that when the time came that I needed them, I might recall their existence, if not the full syntax, and know how to find out more about them in the help files and PDF manuals.

      Local and global macros are a key part of programming Stata; you apparently did not recognize the meaning of "$in" in the code you are trying to understand.

      Stata supplies exceptionally good documentation that amply repays the time spent studying it - there's just a lot of it. The path I followed surfaces the things you need to know to get started in a hurry and to work effectively.

      Stata also supples YouTube videos, if that's your thing.

      Comment


      • #4
        Many thanks to you both-- yes I will start with these other resources-- thanks for keeping me moving forward.

        Comment

        Working...
        X