Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: levelsof


From   "Luhang Wang" <[email protected]>
To   [email protected]
Subject   st: levelsof
Date   Thu, 20 Sep 2007 23:17:20 -0400

Dear all,

I'm trying to take some strings out of a string variable. Suppose data
set Y contains the list of strings, named variable YY, that I want to
take out from a string variable XX in data set X. An example is that
YY takes value "a" and "b", and XX takes "ac" and "bd", the results I
want are "c" and "d".

My code is as following:

***************************************************
use Y,clear
levelsof YY

use X,clear
foreach l of local levels {
           replace XX=subinstr(XX,"`l'","",.)
}

**************************************************
It doesn't work. Could someone tell me what is wrong with my code? Or
is there better method achieving this? Many thanks in advance.

Cheers,
Luhang
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index