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: Mata question on replacing missing values
From
Matthew White <[email protected]>
To
[email protected]
Subject
Re: st: Mata question on replacing missing values
Date
Thu, 22 Dec 2011 10:45:15 -0500
Hi Matt,
How about:
Z = (X :!= .) :* editmissing(X, 0) + (X :== .) :* Y
Best,
Matt
On Thu, Dec 22, 2011 at 9:45 AM, Matthew Baker
<[email protected]> wrote:
> Dear Listers:
>
> I am curious if there is a simple solution to the following
> problem in Mata. I have two vectors (call them X and Y). X has missing
> values, while Y does not. What I would like to do is make a third
> vector, Z, which is composed of X when the value of X is not missing,
> and Y otherwise. For example, if I have X=(5,6,.,.,4)', and
> Y=(1,5,3,2,3)', I would like Z to be Z=(5,6,3,2,4)'. In order:
>
>
> : X,Y,Z
> 1 2 3
> +-------------+
> 1 | 5 1 5 |
> 2 | 6 5 6 |
> 3 | . 3 3 |
> 4 | . 2 2 |
> 5 | 4 3 4 |
> +-------------+
>
> Is there a simple solution?
>
> Thanks in advance,
>
> Matt Baker
>
> --
> Dr. Matthew J. Baker
> Department of Economics
> Hunter College and the Graduate Center, CUNY
> *
> * 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/
--
Matthew White
Data Coordinator
Innovations for Poverty Action
101 Whitney Avenue, New Haven, CT 06510 USA
+1 434-305-9861
www.poverty-action.org
*
* 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/