Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: executing stata commands/programs based on filename or content

From   "Nick Cox" <>
To   <>
Subject   st: RE: executing stata commands/programs based on filename or content
Date   Thu, 2 Sep 2004 18:21:40 +0100

You can do this 

program myprog 
	version 8.2 
	args exptno 

	< stuff > 

	... `exptno'rn.csv 

	... `exptno'dis.csv 


This needs a little care if `exptno' contains spaces. 


Juan Solon

> I am new to writing programs.  I would like to ask for advise on a
> program for standardising our lab reports using stata.
> The bottom line is I would like to type in 1 common 
> identifier , in this
> case the experiment number (exptno)  that is present in the 
> filename and
> the program does the rest, depending on the suffix of the files it
> finds.
> I am at the stage that I have to type
> pgmname exptnodis.csv, exptnorn.csv, and exptnores.csv
> assigning each file to a macro 1-3.
> I want to get to the stage where I type:
> pgmname exptno
> will create three different graphs using the files exptnorn.csv, 
> exptnodis.csv, and exptnores.csv and combine them
> Details
> I am using a quantiative PCR machine in the laboratory and for each
> experiment, I generate three comma separated files.   Each file is
> identified by the experiment number and an identifier that I type in
> from the lab machine.
> Thus, I would have for experiment RQ01, the following files:
> rq01rn.csv
> rq01dis.csv
> rq01res.csv
> Each file is used for a specific graph.  To create the graph requires
> reshaping and creating a few new variables. 
> I currently have a program that i called called qpcr that 
> will work such
> that :
> qpcr rq01rn.csv rq01dis.csv rq01res.csv
> will create three different graphs and save them accordingly.
> I have written a do file to combine the three graphs but this still
> requires me to type in each graph name withine the do file - 
> or I could
> write a program, but it would be similar to the one above and would
> require me to write three different .gph names after the program name
> I want to improve on this so that I only need to type
> qpcr exptname or in this instance, qpcr rq01 
> 1. to create three separate graphs from three different files coming
> from experiment rq01;  and
> 2. to combine them
> I am unsure as to how to proceed next.
> I thought that my first hurdle would be to get stata to execute three
> separate commands based on a common identifier (in this case exptname)
> but each command is to be run on different files, with each 
> file bearing
> the exptname but differing in its suffix.
> I thought that the simplest way to do this was to ask Stata 
> to read the
> file names of the files that begin with rq01 and to run the 
> appropriate
> graph command that I have written based on the differing suffixes (one
> graph for rn, one for dis, one for res).  
> I was then hoping to use the same solution to go on to the next step
> which is to combine three different graphs bearing a common experiment
> name but differing in it suffix to be incorporated into the program
> qpcr.

*   For searches and help try:

© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index