Announcement

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

  • Applying do-file to multiple datasets

    Hello,

    I'm trying to apply the following commands to ten hospital datasets using the local filelist command. My code is as follows:
    -----------------------------------------------------------------------------------------------------
    local filelist: dir"/Users/CDDEP/Downloads" files"*.dta"
    foreach file of local filelist {

    gen double dateofadmission_rc = clock(dateofadmission, "DMY")
    format dateofadmission_rc %tcCCYY-NN-DD_HH:MM:SS

    gen double dateofdischarge_rc = clock(dateofdischarge, "DMY")
    format dateofdischarge_rc %tcCCYY-NN-DD_HH:MM:SS

    gen double reportdate_rc = clock(reportdate, "DMY")
    format reportdate_rc %tcCCYY-NN-DD_HH:MM:SS

    gen mortality_rc="false"
    replace mortality_rc="true" if mortality=="Yes"
    label variable mortality_rc "Mortality"

    gen double dateofdeath_rc = clock(dateofdischarge, "DMY") if mortality_rc=="true"
    format dateofdeath_rc %tcCCYY-NN-DD_HH:MM:SS

    save "/Users/CDDEP/Documents/RESMAP/Fortis/`file'", replace
    clear
    }
    ---------------------------------------------------------------------------------------------------------
    However, the following error comes up after only one iteration:
    "dateofadmission not found r(111)"


    I've visited other threads, but can't seem to figure it out. Any advice would be appreciated.

    Thank you,

    Katie

  • #2
    Maybe you need to add a line like this at the top of the loop?

    Code:
    use "/Users/CDDEP/Downloads/`file'" , clear
    David Radwin
    Senior Researcher, California Competes
    californiacompetes.org
    Pronouns: He/Him

    Comment


    • #3
      Hi David,

      Thank you so much! That solved the issue.

      Best,

      Katie

      Comment


      • #4
        Katie, I find your code is difficult to read. (David must have better eyes than mine.) In future posts, please put code and output between CODE delimiters, as requested in FAQ 12.
        Last edited by Steve Samuels; 18 Oct 2017, 16:44.
        Steve Samuels
        Statistical Consulting
        [email protected]

        Stata 14.2

        Comment

        Working...
        X