Announcement

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

  • How to access a frame with a tempname from a subprogram?

    I am writing an ado file which includes Monte Carlo simulations.

    I define the frame which holds successive simulation results:

    tempname fdata_replicates

    At various times in the program I want to display summary measures of the current variables in this dataframe. Since I need to do this repeatedly, I want to put the relevant commands in a subprogram:

    program displayMonteCarlo
    version 17
    syntax [varlist], datafile(name) [stats(string) ]
    if "`stats'" == "" local stats "mean count min max"
    if "`varlist'" == "" {
    frame `datafile':qui ds
    local varlist `r(varlist)'
    }
    frame `datafile': tabstat `varlist', stat(`stats') columns(statistics) varwidth(30)
    end


    and call this sub program using:

    displayMonteCarlo, datafile(`fdata_replicates')

    This is not working. The subprogram tries to use the current frame, not the frame whose name I am attempting to pass.
    What am I doing wrong??

    Thanks


  • #2
    Perhaps you need a frame create command in there somewhere?
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 19.5 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      The problem is the line when you don't specify a varlist:


      Code:
      syntax [varlist], datafile(name) [stats(string) ]
      By default, if you don't specify a varlist, syntax will fill in the local varlist with all variables in the current frame. This is not what you want. You can change that by using the line

      Code:
      syntax [varlist(default=none)], datafile(name) [stats(string) ]
      instead
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Thank you so much Maarten, it's now working perfectly.
        I didn't know about the default behaviour when there is no varlist specified, I thought it must have something to do with the frames.

        Susan Donath
        University of Melbourne
        [email protected]

        Comment

        Working...
        X