Announcement

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

  • saving serial output as a different Stata file name with each loop

    I am attempting to loop a series of analyses to produce a series of output files with a new, different name from each loop. This work uses a longitudinal dataset that includes data from each sequential day having been added over a period of time. I would like to use the new, daily date variable value (here called "datevariable") for each past day to name each such file.

    In other words, I want to create output using data prior to date q, and save that output; then create and save output using data prior to date q + 1; then same for date q + 2; etc. etc.

    I have unsuccessfully attempted to use the following general approach:

    foreach x of varlist datevariable {

    logistic outcome predictor1 predictor2 if datevariable<`x'

    ***(...followed by lengthy post-regression code, producing a table of values...)***

    save "analytic file as of `x'.dta"

    }
    *

    Code appears to run until reaching the command to save the file. Then I receive the error message "number of quadrature points must be less than or equal to number of obs." I believe that simply putting the `x' value for the running date in the save command is the part that doesn't work, but I am not sure.

    I will be happy to use some other file naming convention such as simple, serial file numbers if that is all that will work in Stata. Hopefully, what I seek to do is possible, otherwise I will have to write a separate code set for each of hundreds of past days.

    Notes: I am working in Stata 12.1. I cannot export data due to data sharing agreements.

    Thank you for any advice you can provide - HC

  • #2
    Also, I have been trying the advice at the following link:

    https://stats.idre.ucla.edu/stata/fa...ames-in-stata/

    ...but the outcome is similar. I can run the code to produce the output, but can't get the file to save while using variations of the "time_string" phrase in the file save command.

    I have always saved a Stata file using syntax such as "C:\Documents and Settings\folder1\folder1a\filename." I am not sure how to get the simpler "myfile_" concept in this link to work without quotations around the command.

    I suspect there are simple answers here...thanks in advance.
    Last edited by Holden Crenshaw; 22 Apr 2018, 13:01.

    Comment


    • #3
      You'll increase your chances of a helpful answer by follwoing the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex.
      set trace on is often helpful in debugging such problems. Also, a bunch of display statements can help.

      But "number of quadrature points must be less than or equal to number of obs." must refer to the logit. You don't have enough observations. Indeed, you must have almost no observations. Try a regression to see how many usable observations you have. Do summary on the variables.

      Comment

      Working...
      X