Announcement

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

  • Where is program_name stored?

    Dear All,

    I have a program as follows:

    program BSE_02052018
    version 12
    syntax, MAINdirectory(str)


    .
    .
    .

    I want to know how can I store the name BSE_02052018 in a local/global macro? I have similar programs which start with BSE_. I want to store the program names so as to use them within my programs. Another reason to do so is that I also want to extract the digits (02052018) and use them for analysis by removing BSE_ from the program name string.

    Thanks,
    Amit


  • #2
    The simplest solution is to create the macro the moment you create the program. I suppose you thought of that, and decided that that was not a solution. Now we need to know why. In general, we need to know more about what you are trying to do, e.g. why you came up with those funky names.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Maarten, I thought of the simplest solution only i.e. creating a macro and store the program_name in it. But I could not do so.

      Just to give you an idea of what I am trying to do:
      I have a program which is named as BSE_02052018.ado. This program is to be run on BSE_02052018.dta. This program is nothing but a collection of various Stata commands which are to be run on the dta file. Similarly, I have 100s of files and 100s of corresponding .ado programs.
      Before running each program, I need to confirm (match) datafile name with ado program name. I also need to use the date which is substring of the program name. So, to accomplish this, I need to store program_name in a macro to use it for matching purposes. I hope my query is clear to the readers.

      I am just a Stata learner, so seeking help from Stata experts here. Any solution to this would be very helpful for me. Kindly let me know how to store program_name in a local/global macro?

      Best
      Amit

      Comment


      • #4
        I still find it hard to follow your approach but the answer to your initial question is this: program_name of an ado-file is stored as program_name.ado wherever you have stored program_name.ado. Stata will complain if the (first) program defined in program_name.ado is called anything other than program_name if you try and run that program.

        From what you describe, I am guessing that you probably have (or want to have) something like

        Code:
        local dta_files : dir "directory" files *.dta
        foreach dta of local dta_files {
            local program_name : subinstr local dta ".dta" ""
            `program_name'
        }
        If this is what you want, you do not actually need to define programs in ado-files; you would rather have do-files and put the above code into master.do.

        Best
        Daniel

        Comment

        Working...
        X