Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

RE: st: ado file help


From   tashi lama <[email protected]>
To   <[email protected]>
Subject   RE: st: ado file help
Date   Tue, 14 Aug 2012 14:26:56 +0000

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: [email protected]
> To: [email protected]
>
> 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 <[email protected]> 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: [email protected]
> >> To: [email protected]
> >>
> >> 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 <[email protected]> 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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index