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]

st: Replace observations within variables


From   Fatma Usheva <[email protected]>
To   [email protected]
Subject   st: Replace observations within variables
Date   Thu, 19 Sep 2013 12:37:40 +0200

Dear All,

I have a dataset with more than 400 variables, which have a common prefix, e.g. data_0, data_1, data_2, etc.
I also have state and municipality IDs, where within a state I could have multiple municipalities.

What I want to do is to replace observations within data_* variables for selected municipalities only, keeping state municipality codes unchanged. 

The way i do it now is the following:

	
foreach var of varlist data_* {

capture noisily replace `var'=`var'[11] if municipality==2001 
capture noisily replace `var'=`var'[16] if municipality==26043

}


where under [11] is municipality 2002, under [16] is municipality 3003, etc.

Is there a faster way to do this, without me going through the data trying to find which observation number corresponds to each municipality in interest (2002, 3003, 4003, etc.)?

Thanks for your help!
Fatma



*
*   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