View Full Version : how to delete a previous command
01-21-2011, 05:56 PM
I am new to STATA and I can use the basic command.
However something that I cannot absolutely understand is how to delete a previous command.
Suppose I have deleted some data doing "keep if male == 0". Now all the data available will be only for female -as 0 means female-.
What though if I want to delete the command "keep if male == 0" and come back to the full data set for both female and male?
I have tried to look for it on the internet and I did find something but it did not work out.
I really need your help...!
Thanks a lot!
01-21-2011, 07:41 PM
You can't undelete data, but you can keep a copy of the dataset before dropping values (eg -preserve-, -tempfile- or -snapshot-). However, such tricks are not usually necessary unless you're doing something relatively complicated. What exactly are you trying to do with your data?
01-22-2011, 05:34 AM
Bukharin, thanks a lot for your prompt answer :)
What exactly are you trying to do with your data?
I have a large data set, given to me by my supervisor, something like 500.000 observations. And i have to work on this data to extrapolate information.
But what you have answered me, surprises me.
Suppose -which is actually want I want to do- I want to work only on a small bit of these data: I want just work with data from people who are in the bottom quantile of the monthly consumption distribution.
I need this as I want to see if female participation to school within the bottom quantile monthly cons distribution differs significantly from that one in the higher monthly consumption distribution.
Once I know this, I want to come back to the full data set so that I can repeat the same thing for the top quantile monthly consumption distribution.
I thought -and maybe someone told me- there was a command through which you could simply delete the previous command. Something like "ok, now that I have seen what happens for this part of the distribution, let's come back to the full data set".
Otherwise what I should do?
What I have done so far is that once I have kept only the poorer people, since I could not come back to the full data set I just quit Stata and then opened it again. But since it is quite a pain to do this every time, I was just hoping to find some command which let me have again the full data set.
01-22-2011, 06:02 AM
I'm not sure you really need to delete and undelete observations for that... why not just use -if-, eg:
mean participation if male==0
mean participation if male==1
It's also very much worth learning how to use -by- (see the user's manual).
If there are several steps involved and you don't want to keep typing "if" then -preserve- and -restore- are probably the best bet:
keep if male==0
... do whatever you need...
keep if male==1
... do the same thing...
If you posted your actual code we may be able to figure out something more efficient, but the above should at least do what you need.
01-22-2011, 07:19 AM
Bucharin: Thank you very much indeed!
Yeah, that was exactly the command I was looking for! I have just tried it out and works perfectly.
Amazing! Now I can simply can back to the original sample once I have finished looking at only a small part of it.
I am wondering now:
can this preserve command works at different level?
when I work with poor ones I may also want to keep only the ones who attend to secondary school.
keep if monthly_consumption < = 3200
keep if level_of_schooling == 10 (which means secondary)
If I then type restore it brings me back to the sample before the first Keep command and I have seen that if I try to write another preserve before the second keep it does not work.
Is there any command to go back to the full data set before the second keep?
Thanks a lot!!!
01-23-2011, 05:48 PM
No, you can't do nested preserves. You will need to use one of the other solutions I mentioned in my first post (-tempfile- or -snapshot-). But a better option would be to post the code you're using so that we can take a look and see if there's a more efficient way of doing things.
01-24-2011, 01:40 PM
sorry, am really new and when you say :
But a better option would be to post the code you're using.
..what do you mean exactly? :o
I should post the command that I type?
01-24-2011, 01:56 PM
Yup. For example if I was to post some R code (which I do regularly) I might write something like this:
inside of my post. I wrapped that bit in HTML tags so that it wouldn't interpret the CODE tags. If I don't wrap it in HTML tags then it appears like this:
You can 'quote' what I wrote to see what I'm talking about if it helps.
Powered by vBulletin™ Version 4.1.3 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.