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 Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: ado file help
Date   Mon, 13 Aug 2012 22:25:46 +0100

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/


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