+ Reply to Thread
Results 1 to 8 of 8

Thread: how to delete a previous command

  1. #1
    Points: 2,589, Level: 30
    Level completed: 93%, Points required for next Level: 11

    Posts
    93
    Thanks
    8
    Thanked 0 Times in 0 Posts

    how to delete a previous command



    Hi there!

    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!
    belfagor

  2. #2
    RoboStataRaptor
    Points: 7,341, Level: 56
    Level completed: 96%, Points required for next Level: 9
    bukharin's Avatar
    Location
    Sydney, Australia
    Posts
    1,018
    Thanks
    9
    Thanked 240 Times in 233 Posts

    Re: how to delete a previous command

    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?

  3. #3
    Points: 2,589, Level: 30
    Level completed: 93%, Points required for next Level: 11

    Posts
    93
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: how to delete a previous command

    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.

    ...is there?

  4. #4
    RoboStataRaptor
    Points: 7,341, Level: 56
    Level completed: 96%, Points required for next Level: 9
    bukharin's Avatar
    Location
    Sydney, Australia
    Posts
    1,018
    Thanks
    9
    Thanked 240 Times in 233 Posts

    Re: how to delete a previous command

    I'm not sure you really need to delete and undelete observations for that... why not just use -if-, eg:
    Code: 
    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:

    Code: 
    preserve
    keep if male==0
    ... do whatever you need...
    restore
    
    preserve
    keep if male==1
    ... do the same thing...
    restore
    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.

  5. #5
    Points: 2,589, Level: 30
    Level completed: 93%, Points required for next Level: 11

    Posts
    93
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: how to delete a previous command

    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?
    I mean:
    when I work with poor ones I may also want to keep only the ones who attend to secondary school.
    Something like:

    preserve
    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!!!

  6. #6
    RoboStataRaptor
    Points: 7,341, Level: 56
    Level completed: 96%, Points required for next Level: 9
    bukharin's Avatar
    Location
    Sydney, Australia
    Posts
    1,018
    Thanks
    9
    Thanked 240 Times in 233 Posts

    Re: how to delete a previous command

    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.

  7. #7
    Points: 2,589, Level: 30
    Level completed: 93%, Points required for next Level: 11

    Posts
    93
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: how to delete a previous command

    Hi!

    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?

    I should post the command that I type?

  8. #8
    RotParaTon
    Points: 46,173, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardFrequent PosterCommunity AwardMaster Tagger
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,067
    Thanks
    211
    Thanked 1,605 Times in 1,375 Posts

    Re: how to delete a previous command


    Yup. For example if I was to post some R code (which I do regularly) I might write something like this:
    HTML Code: 
    [code]
    plot(density(rnorm(1000,7,10)))
    [/code]
    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:
    Code: 
    plot(density(rnorm(1000,7,10)))
    You can 'quote' what I wrote to see what I'm talking about if it helps.

+ Reply to Thread

Similar Threads

  1. Help: lost suddenly all the previous work!
    By belfagor71 in forum Stata
    Replies: 2
    Last Post: 02-28-2011, 01:37 PM
  2. SPSS => How to delete cases?
    By PetterBB in forum Psychology Statistics
    Replies: 2
    Last Post: 12-04-2010, 12:27 AM
  3. how do i delete my account on this website
    By pad1w07@soton.ac.uk in forum Statistics
    Replies: 2
    Last Post: 09-26-2008, 12:22 PM
  4. Replies: 4
    Last Post: 02-15-2006, 01:29 PM
  5. Replies: 2
    Last Post: 02-15-2006, 11:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats