Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: RE: From: [email protected]
From
Eric Booth <[email protected]>
To
"<[email protected]>" <[email protected]>
Subject
Re: st: RE: From: [email protected]
Date
Fri, 13 Aug 2010 20:43:27 +0000
<>
On Aug 13, 2010, at 3:16 PM, Martin Weiss wrote:
>
> But the missings are back once the -merge-r is done.
> Let`s summarize: We can twist it and bend it as much as we like, there are
> no "empty cells" in Stata...
Right. From David's statement "without disturbing the other variables in the dataset" I got the impression that he wanted to do what Excel does when you right click on some cells and choose to "Delete..">"Shift Cells Up". Sorting moves all the rows together while extracting "x", removing/dropping the missing cells, and remerging does what I think David is asking for.
On Aug 13, 2010, at 3:24 PM, Maarten buis wrote:
> It is absolutely crucial that the values that
> belong to the same observations (i.e. a row in your
> dataset) always stay together. You can move entire
> rows up or down, or you can move columns left or right,
> but you must never move individual cells up or down
> or left or right. If that happens your entire dataset
> has instantly become completely worthless.
>
This is a good warning and is certainly true in (almost) all cases, but I assumed that David knows why he wants to move the data up the column and its effect on the data integrity.
BTW, I have had situations where values in one or more columns are shifted down by a couple of rows, and I have to shift them up so that they are properly aligned (e.g., data that was extracted from a PDF or HTML page where the row spacing is interpreted by Acrobat or some other program).
~ Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
On Aug 13, 2010, at 3:16 PM, Martin Weiss wrote:
>
> <>
>
> But the missings are back once the -merge-r is done.
>
>
>
> . li
>
> +---------------------------------+
> | a b x _merge |
> |---------------------------------|
> 1. | 9 5 .998 matched (3) |
> 2. | 1 5 .658 matched (3) |
> 3. | 1 5 7.801 matched (3) |
> 4. | 1 5 . master only (1) |
> 5. | 9 5 . master only (1) |
> |---------------------------------|
> 6. | 1 5 . master only (1) |
> 7. | 9 5 . master only (1) |
> 8. | 1 5 . master only (1) |
>
>
>
> Let`s summarize: We can twist it and bend it as much as we like, there are
> no "empty cells" in Stata...
>
>
> HTH
> Martin
>
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Eric Booth
> Sent: Freitag, 13. August 2010 22:12
> To: <[email protected]>
> Subject: Re: st: RE: From: [email protected]
>
> 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
> [email protected]
> 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: [email protected]
>> [mailto:[email protected]]
>> Sent: Freitag, 13. August 2010 21:48
>> To: Stata List
>> Subject: st: From: [email protected]
>>
>> 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/