Bookmark and Share

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: Replace with missing value


From   Alex Olssen <[email protected]>
To   [email protected]
Subject   Re: st: Replace with missing value
Date   Fri, 12 Apr 2013 20:23:42 +1000

Here is an example. You can check that it does what you want. You must be careful about the first 30 observations. I only start your replacing from the 31st days. You can manually adjust this part to suit your needs.

clear
set seed 1
set obs 10000
gen days = _n
gen x = round(100 * runiform())
gen y = round(100 * runiform())
replace y = . if y > 95
tsset days
forvalues d = 1/30 {
  replace x = . if L`d'.y == . in 31/l
}

Regards,
Alex

On 12/04/13 7:35 PM, André Gyllenram wrote:
So i have a simple problem. I have a time series and two variables. I have a variable that is nonmissing and i would like to replace it with a missing value if my other variable has a missing value somwhere during the last 30 days. Can anyone help me?

Kind regards
André 		 	   		
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index