Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: RE: From: D.Ronayne@warwick.ac.uk


From   Eric Booth <ebooth@ppri.tamu.edu>
To   "<statalist@hsphsun2.harvard.edu>" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: RE: From: D.Ronayne@warwick.ac.uk
Date   Fri, 13 Aug 2010 20:11:47 +0000

If you want the non-missing cells to shift up to column and the other variables to stay fixed, you could create another dataset with just "x", remove the missings and merge it back in using a 1:1 merge on the row (_n):

***********
clear*

inp a x b 
9 0.998 5
1 . 5
1 . 5
1 . 5
9 0.658 5
1 . 5
9 7.801 5
1 . 5
end

preserve
keep x
drop if mi(x)
save using.dta , replace
restore

drop x
merge 1:1  _n using using.dta
li
***********
~ Eric

__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu
Office: +979.845.6754


On Aug 13, 2010, at 3:00 PM, Martin Weiss wrote:

> 
> <>
> 
> You can -sort- on the variable to assemble all the values other than
> missings at the top. But the other variables will move as well...
> 
> ***********
> clear*
> 
> inp x 
> 0.998
> .
> .
> .
> 0.658
> .
> 7.801
> .
> end
> 
> gen byte othervar=_n
> so x
> 
> list, noo
> ***********
> 
> 
> HTH
> Martin
> 
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] 
> Sent: Freitag, 13. August 2010 21:48
> To: Stata List
> Subject: st: From: D.Ronayne@warwick.ac.uk
> 
> Dear all,
> 
> I wish to delete "cells" (not observations, aka rows) that have missing
> values for variable x only within x. Hence,
> 
> "drop if x==."
> 
> would not work because it will delete the observations across all
> variables, to explain graphically, I want something that looks like this:
> 
> variable x
> 0.998
> .
> .
> .
> 0.658
> .
> 7.801
> .
> 
> to become:
> 0.998
> 0.658
> 7.801
> 
> without disturbing the other variables in the dataset. Manually
> manipulating in Excel is not an option because this is done half way
> through a do file and must be done by written commands. Stata is very easy
> to use to drop variables and observations, but can it delete specific
> "cells"?
> 
> Can anyone help here?
> 
> Any advice much appreciated,
> David
> *
> *   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/




*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index