Statalist


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

RE: st: how to use data editor with do-files in STATA11


From   Amado David Quezada Sanchez <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: how to use data editor with do-files in STATA11
Date   Tue, 26 Jan 2010 21:20:56 -0600

Hi Eric,

Thank you very much! The pause command works perfectly! Although I agree that the data editor is not the best way to go I use it mainly when other specialists have to run my code and make corrections according to their expertise. I have use it as well for some programs that receive input from the user in a windowed fashion.

Amado Q.



________________________________________
De: [email protected] [[email protected]] En nombre de Eric Booth [[email protected]]
Enviado el: martes, 26 de enero de 2010 11:27 a.m.
Para: [email protected]
Asunto: Re: st: how to use data editor with do-files in STATA11

>>

I had a copy/paste error in the "pause on" line of
my previous posting, it should have read:

*------------begin
pause on
sysuse auto, clear
cap assert for==0 in 70
di _rc
if _rc==9 {
        pause
        **now you can edit the var
        **if the assertion is false
        **press "q" after editing**
        }
desc, sh
*------------end



~ Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754


On Jan 26, 2010, at 11:19 AM, Eric Booth wrote:

>>>
>
>> edit if mpg_class==3 & foreign==1
>> edit if mpg_class==1 & foreign==0
>> edit if length>180 & mpg_class==2
>
> You should hardcode your edits in your do-file so that you can keep track of changes
> and easily track mistakes in your code, so if you are going to edit price if the conditions above
> are true, simply insert the statements:
>
> **(let's assume you want to edit just one observation/row)**
> replace price = 5 in 10 if mpg_class==3 & for==1
> replace price = 10 in 11 if mpg_class==1 & for==0
> replace price = 20 in 12 if leng>180 & mpg_class==2 & !mi(length)
>
> If you don't want these changes to be permanent to the dataset you can preserve/restore before
> and after these changes and save it as a separate dataset.
>
> Finally, if you are really sure that you want to stop the do-file and edit the dataset,
> you can use -pause- and -assert-, but I wouldn't advise it:
>
> *------------begin
> sysuse auto, clearpause on
> sysuse auto, clear
> cap assert for==0 in 70
> di _rc
> if _rc==9 {
>       pause
>       **now you can edit the var
>       **if the assertion is false
>       **press "q" after editing**
>       }
> desc, sh
> *------------end
>
> ~ Eric
> __
> Eric A. Booth
> Public Policy Research Institute
> Texas A&M University
> [email protected]
> Office: +979.845.6754
>
>
>
> On Jan 26, 2010, at 10:58 AM, Amado David Quezada Sanchez wrote:
>
>> Hello,
>>
>> I'm used to run big do-files for cleaning data. In several parts of my code I write "edit if..." so I can make specific corrections on the go. That would not be a problem in earlier versions of STATA (like STATA 9 or 10) because the execution of do-files stops until you're done with the first data edition window and then continues running the code until you reach the next data edition window.
>>
>> In STATA 11 the executed do-file doesn't stop. I suspect that's because in earlier versions of STATA all modifications are done until you confirm to accept changes or close the window, so the preserve command is executed first in case you would like to reverse all corrections. That helps a lot because you can, as I said, make corrections in interactive manner as the do-file runs.
>>
>> A very simple example:
>>
>> sysuse auto, clear
>> gen mpg_class=1 if mpg<20
>> replace mpg_class=2 if mpg>=20 & mpg<30
>> replace mpg_class=3 if mpg>=30
>> /* Let's say I would make modifications for three   */
>> /* specific situations, in extense do-files I would */
>> /* have many operations between the following lines */
>> edit if mpg_class==3 & foreign==1
>> edit if mpg_class==1 & foreign==0
>> edit if length>180 & mpg_class==2
>> /* If you run the whole code with STATA 11 you don't */
>> /* have the chance to make modifications or */
>> /* corrections on the go, you only get the last data */
>> /* editon window */
>>
>> I'm very interested to make STATA 11 stop at each data edition window when you run the whole code. Any suggestion would be greatly welcome.
>>
>> Thank you,
>>
>> Amado Quezada
>> National Institute of Public Health
>> Cuernavaca, Mexico
>>



*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index