Statalist The Stata Listserver


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

st: RE: FW: Cleanup of messy variable


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: FW: Cleanup of messy variable
Date   Thu, 19 Oct 2006 14:06:50 -0500

Does something like this help:

clear
input str30 game
"1 2 3 4 5 7 8 998            "
"	1 2 3 4 5 898         "
"	1 2 3 51098           "
"	1 2 4 5 7 898         "
"	1 2 498               "
"	1 2 81098             "
"	1 2 898               "
"	1 298                 "
"	1 3 898               "
"	1 398                 "
"	1 4 5 898             "
"	1 4 598               "
"	1 4 8 9 5 798         "
"	1 4 898               "
"	1 498                 "
"	1 5 2 798             "
"	50 85998              "
"	5898                  "
"	77                    "
"	                   88 "
"	88                    "
"	89 898                "
"	99                    "
end
l
replace game = trim(game)
gen byte  game98 =  substr(game, -2,.) == "98"
gen  game_foo= subinstr(game, "98", " " ,1)

foreach  i in 1 2 3 4 5 6 7 8 9 10 77 88  99  {
	gen byte game`i' = regexm(game_foo, "`i'") 
}
replace game7 = 0 if game77 == 1
replace game8 = 0 if game88 == 1
replace game9 = 0 if game99 == 1
drop game_foo
egen does_gamble = rowtotal(game1-game10)
replace does_gamble = 1 if does >0 &  !mi(does_gamble)
tab does_gamble
//Proportion of adults participating in gambling
tabstat game1-game10,
		
		      
Scott



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