Hi there,
In the code below my goal is to convert the local below into a neat list by converting "R140/R143" to "R140" "R141" "R142" "R143" and so on. Below is my code, it seems to be running correctly but it crashes in the last line, when I ask it to display local GC so I can make sure the local has been transformed as I expected it to transform. How do I have stata display a local back to me?
cls
clear
local GC `" "R070" "R140/R143" "R09" "R093" "R12" "R120" "R150 / R152" "R190 / R196" "R200 / R203" "R208 / R209" "R21" "R210" "R22" "R220 / R224" "B078 / B079" "K00" "K000 / K009" "K01" "K010 / K011" "K02" "K020 / K029" "K03" "K030 / K039" "K04" "K040 / K049" "K05" "K050 / K056" "K06" "K060 / K062" "K068 / K069" "K07" "K070 / K076" "K078/ K079" "K08" "K080 / K085" "K088 / K089" "K09" "K090/K092" "K098 / K099" "K10" "K100 / K103" "K108/K109" "K11" "K110 / K119" "'
set trace off
foreach x of local GC{
if strpos("`x'","/")>0 & strpos("`x'","0")!=2 {
local CODE =substr("`x'",1,1)
*di "`x'"
*di "`CODE'"
foreach a in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z {
local x=subinstr("`x'","`a'","",.)
}
di "`CODE'"
*di "`x'"
local x=subinstr("`x'"," ","",.)
forvalues z=`x' {
di "`CODE'`z'"
}
}
}
foreach x of local GC{
if strpos("`x'","/")>0 & strpos("`x'","0")==2 {
local CODE =substr("`x'",1,2)
*di "`x'"
*di "`CODE'"
foreach a in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z {
local x=subinstr("`x'","`a'","",.)
}
di "`CODE'"
*di "`x'"
local x=subinstr("`x'"," ","",.)
forvalues z=`x' {
di "`CODE'`z'"
}
}
else {
di "`x'"
}
}
}
di "`GC'"
Related Posts with Help with Strpos
Create a new variable based on two other variablesHi Statalist. I would like to create a variable (total household assets) based on the values of tot…
Question about Mixed effect modelDear all. I am looking for wise advice on what happened to my mixed effect model from the STATA expe…
Dummy VariableHow do I create a dummy variable which takes the value 1 in a household when first two children are …
Help with Longitudinal SEM - (Missing Means in Output)Hello! I'm having trouble running SEM on longitudinal data (4 waves - (same group followed over tim…
Help create a person ID for panel dataDear Statalisters, I would like to ask for advice regarding creating person ID variables from a hou…
Subscribe to:
Post Comments (Atom)
0 Response to Help with Strpos
Post a Comment