Announcement

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

  • Save tempfile Error Message

    Hello guys,

    I am trying to merge two datasets. I am imputing these datasets from two difference location (directories/folders). I have two do files, one for each data set. The purpose of the do files is just to clean the datasets and prepare them for merge. I don't need the clean version of these two datsets but just the final merge that is why I am trying to use the tempfile option. Below you can see "part" my do files (all the cleaning commands are omitted).

    Code:
    ***** IMPORT DATA
    clear
    cd "H:\MMM\Datasets\Folder1"
    use data1_Raw
    
    sort ID
    tempfile data1
    save `data1'
    Code:
    ***** IMPORT DATA - ADMISSION DATA
    clear
    cd "H:\MMM\Folder2"
    use  data2_Raw
    
    sort ID
    
    merge ID using `data1'
    This is the error message I got.
    Code:
     
    (note: you are using old merge syntax; see [D] merge for new syntax)
    filelist required
    r(100);

    Any Ideas??
    Last edited by Marvin Aliaga; 08 Jun 2016, 13:13.

  • #2
    Temporary names are local to the locale (nonce word) in which they are defined, meaning the interactive session, program, do-file, do-file editor contents or even chunk of code selected in that editor in which that temporary name is defined..

    Also, a rule when macro references are being evaluated: a name that isn't recognised will be replaced by an empty string.

    My guess is that you are setting up the temporary name for the file in a locale different from that in which you refer to it.

    Consider the error message carefully: merge wants a filelist but can't see one. But you think you supplied a temporary file name. Why didn't it work? Because code in the locale you are using can't see the definition.

    Warning: You won't find locale as a term in StataCorp documentation. It's just my own name for wherever a local macro or equivalent (here a temporary name for a temporary file) is defined. I gave in the first sentence a longer statement of what that might mean.

    Bottom line: Your own statement implies the use of two different do files. But references to the locals in one within another can't work. That's what local means.

    Comment


    • #3
      You need to specify -merge 1:1- (or 1:m or m:1) as the case may be.

      But after you fix that, you will encounter another problem. You saved your tempfile `data1' in H:\MMM\Dataset\Folder 1. But at the time you issue your -merge- command you are working in H:\MMM\Folder 2, so Stata will not find the file. So you have to make it

      Code:
      merge 1:1 /* or whatever */ ID using "H:/MMM/Datasets/Folder1/`data1'"
      Note, by the way that I used /, not \, as the delimiter in the path. This is important. If you use \, you will end up with \`data1. But \` is recognized by Stata's parser as a literal ` character rather than as the start of a local macro reference, which would also cause your program to fail. So you must use / when specifying this pathname. Actually, it's a good idea to get in the habit of always using / in pathnames in Stata. It never hurts: even in Windows, Stata knows what you mean here. And sometimes it saves you from a bug that is very elusive to spot visually.

      Comment

      Working...
      X