Announcement

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

  • Error naming output files from macro

    Hello,

    looping over a series of input files, I want to create a series of output files and name them using a macro.

    Based on this post, I wrote this code:

    Code:
    foreach f of local files_DAX {
    
        use `f', clear
    
    [Part of the code that works properly]
    
        tempvar newfilename
        gen `newfilename' = index + "_" + name_short + "_" + isin + "_" + string(year)  + ".dta"
        disp `newfilename'
    
    * Save cleansed dataset
    
        save "/mnt/HDD/martin/Xetra Database/Output Data/2012/DAX/`newfilename'", replace
    The macro generates the proper name for the output file. However, the output file itself does not receive the proper name, as I get the following ouput:

    DAX_ADIDAS_DE000A1EWWW0_2012.dta
    file /mnt/HDD/martin/Xetra Database/Output Data/2012/DAX/__000000.dta saved

    DAX_MERCK_DE0006599905_2012.dta
    file /mnt/HDD/martin/Xetra Database/Output Data/2012/DAX/__000001.dta saved

    DAX_SIEMENS_DE0007236101_2012.dta
    file /mnt/HDD/martin/Xetra Database/Output Data/2012/DAX/__000002.dta saved

    etc.
    I suppose that there is an issue with the quote marks, but my other attempts did not produce any output file at all.

    What am I doing wrong?

    Best,
    Martin
    Last edited by Martin Valuet; 02 Jul 2020, 10:22.
Working...
X