Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: ado file help


From   Nick Winter <njgwinter@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: ado file help
Date   Tue, 14 Aug 2012 10:41:01 -0400

If that is literally what you typed, then

(1) you should not capitalize the options when you issue the command. The capitalization in the syntax statment tells Stata the minimal abbreviation for each option.

(2) In the program, you should similarly not capitalize the name of the local macro when you refer to it. So it would be ... source_id==`broker_id' ...

(3) you misspelled the "brokerid" option.

Nick winter

On 8/14/2012 10:26 AM, tashi lama wrote:
Ok. The confusion I had was my arguments were either varlist/namelist/anything  and hence I was reading and I quote from Stata "If you type nothing, the command doesn't allow a varlist/namelist/anything". In any case, I had
.....
syntax,STARTdate(str) ENDdate(str) BROKERid(numeric) GRAPHtype(str)
...
obdc load, exec("select date(read_date), count(*) from readership where source_id==`BROKER_id' and date(read_date) between '`STARTdate'' and '`ENDdate'' group by date(read_date)")
if "`GRAPHtype'"=="pie" {
......
..
end

and when I run
dd, STARTdate("2011-01-01") ENDdate("2011-01-20") BROKERod(6429) GRAPHTtype("pie")
stata isn't happy and throws back invalid syntax.

----------------------------------------
Date: Tue, 14 Aug 2012 01:42:08 +0100
Subject: Re: st: ado file help
From: njcoxstata@gmail.com
To: statalist@hsphsun2.harvard.edu

Daniel's advice is excellent. More directly, answers are

1. No.
2. No.

You don't need varlist, namelist, or anything as the four things you
want to specify on the command line are all definable as arguments to
options. From your own question that would be sufficient.

Nick

On Mon, Aug 13, 2012 at 11:01 PM, tashi lama <ltashi32@hotmail.com> wrote:
Sorry Nick, this doesn't help much.
1. Do we not need to define varlist/namelist/anything after syntax
2. How do you put it as macro in the query. Is it going to be
syntax anything, STARTdate(str) ENDdate(str) BROKERid(numeric) /* anything because the arguments are not varlists
odbc load, exec("select date(read_date), count(*) from readership where source_id=`BROKER_id' and date(read_date) between '`STARTdate'' and '`ENDdate'' group by date(read_date)")
or
odbc load, exec("select date(read_date), count(*) from readership where source_id=`anything list' and date(read_date) between '`anything list'' and '`anything list'' group by date(read_date)")

----------------------------------------
Date: Mon, 13 Aug 2012 22:25:46 +0100
Subject: Re: st: ado file help
From: njcoxstata@gmail.com
To: statalist@hsphsun2.harvard.edu

As you want to write a program, you will find it much easier to write
it in Stata style

program dd
syntax , STARTdate(str) ENDdate(str) BROKERid(str) GRAPHtype(str)

<whatever>

end

Nick

On Mon, Aug 13, 2012 at 9:41 PM, tashi lama <ltashi32@hotmail.com> wrote:

I wrote a do-file a while ago with 4 arguments as follows:

begin dofile dd.do
clear
set more off
args graph_type broker_id start_date end_date
qui odbc query indigo
odbc load, exec("select date(read_date) as date, count(*) as hits from readership where firm_id=`broker_id' and date(read_date) between '`start_date'' and '`end_date'' group by date")
if "`graph_type''=="pie" {
............
exit
}
else {
........
exit
}

The problem with this code was because args is a positional macros, whatever I enter as `1' would be graph_type, `2' as broker_id and so on. If I enter the following
do dd 2011-01-01 pie 2011-01-20 6429 => stata would take 2011-01-01 as graph_type and yields error.

This makes this code not so convenient and I would like to attempt to write a code (possible ado file with synatx) so that the code would run when

dd graph_type="pie" start_date="2011-01-01" broker_id=6429 end_date="2011-01-20"
or
dd end_date="2011-01-20" graph_type="line" start_date="2011-01-01" broker_id=6429

I tried but got stuck

begin adofile dd
clear
program dd
syntax anything
qui odbc ...
odbc load, exec(".....
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/ 		 	   		
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index