From | David Kantor <dkantor@jhu.edu> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Structure for making line by line changes? |
Date | Mon, 28 Apr 2003 10:33:44 -0400 |
At 05:49 PM 4/25/2003 -0700, Daniel Sabath wrote:
Hi David,[...]
Thank you. A lot of what you mentioned makes sense. Please see my previous reply to Fred and Nick as I think I may have explained myself a little clearer there.
Now on to the nitty gritty...
It was quite a surprise to find out that the if statement only evaluates its conditions once and not on each row. As a result, i'm not sure when it would be useful.It is very useful, usually about things that are above the level of individual observations. Here's an example:
At what point are scalars and macros evaluated? Can you reset the value in the middle of the run depending on other calculations? IEThey are evaluated whenever you reference them. They are set when you set them. But you can only set them *between* any -generate- or -replace- operations. (-generate- and -replace- operate on variables.)
x = 0;
replace y = z if x < 10, x++
> 2: Most Stata statements that operate on the data do so on the wholeYou are correct here. And this is truly a fundamental difference between Stata and the others. Once you get this, you are on your way to using Stata effectively. It is a more wholistic approach to handling the data. (Also, it may help to remember that what you said applies to commands entered interactively. A do file is just a way of preparing your commands.)
> dataset at once. (Actually, there is a sequential aspect to the action that
> processes the statement, but you usually don't need to think about it.) It
> may help to remember that, for example, in you code...
> gen k = 2
> gen l = 3
>
> first, k is created and set to 2 for all observations; then l is created
> and set to 3 for all observations.
I believe that this is one of the fundimental differences (and a hard one to get your head around) between stata and other stats languages. The implicit loop through the data exists on each *line* of the do file and not around the program as a whole. Other languages work on the data a line at a time and allow you to make as many calculations / modifications as you like before proceeding. Please correct me if I am missing something.
© Copyright 1996–2025 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |