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


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: ado file
Date   Mon, 13 Aug 2012 17:13:52 +0100

In your case, what is important is the difference between the program
and the .ado file that defines it.

1. First time you type -dd-, Stata looks for a command -dd- that it
knows about, doesn't find one, but does find an .ado file -dd.ado-. So
it runs -dd.ado- and what happens is that

clear

Data are -clear-ed.

program dd
...
end

Program -dd- is defined to Stata.

2. Second time you type -dd, Stata looks for a command -dd- that it
knows about, but this time it does find one.  You just defined -dd- by
a series of commands starting with -program- and ending with -end-.
But this time there is no -clear-.

There are at least two takes on what you could do. One is that you
could revise your program -dd- so that -clear- is included in the
program.

Another is that this is an example of premature programming, defined
as writing a program that isn't needed. There is almost no generality
in your program and it might as well be a do-file with arguments. But
then again there is no harm done either.

Nick

On Mon, Aug 13, 2012 at 4:48 PM, tashi lama <[email protected]> wrote:
>
> I am writing a simple ado-file where I am generating a dataset using sql query and listing the variable using syntax command. Here is my code
> clear
> program dd
> qui odbc query indigo_dev71
> odbc load, exec("select date(read_date) as date, count(*) as hits from readership where source_id=6429 and date(read_date) between '2011-01-01' and '2011-01-20' group by date(read_date)")
> syntax [varlist]
> list `varlist'
> end
> exit
>
> when I execute ado file    .dd date hits
>          date    hits |
>      |------------------|
>   1. | 01jan2011    127 |
>   2. | 02jan2011    315 |
>   3. | 03jan2011   4438 |
>   4. | 04jan2011   3978 |
>   5. | 05jan2011   3896 |
>      |------------------|
>   6. | 06jan2011   4981 |
>   7. | 07jan2011   4310 |
>   8. | 08jan2011    540 |
>   9. | 09jan2011    567 |
>  10. | 10jan2011   5572 |
>      |------------------|
>  11. | 11jan2011   4261 |
>  12. | 12jan2011   4184 |
>  13. | 13jan2011   4218 |
>  14. | 14jan2011   4894 |
>  15. | 15jan2011   1113 |
>      |------------------|
>  16. | 16jan2011    343 |
>  17. | 17jan2011   1154 |
>  18. | 18jan2011   3981 |
>  19. | 19jan2011   5669 |
>  20. | 20jan2011   3685 |
>
> Great. But when I run second time  .dd date
> Stata returns you must start with an empty dataset. I have a "clear" command at the top of my adofile to start with a fresh memory. Could someone please explain? Also, does adofile name have to be identical to the program name? Meaning, my program name here is dd. Do I have to have a adofile dd.ado? If they could be different, how do I execute?

*
*   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