I now face the following problem:
Code:
webuse auto,clear
lab var make "STATA#1, 90"
lab var price "STATA#11, 90"
lab var mpg "STATA#22, 91"
lab var rep78 "STATA#2, 91"
lookfor make price mpg rep78
local varlist= r(varlist)
local counter=0
foreach var in `varlist' {
local varlab: var lab `var' //extract the whole variable label string
//di "`varlab'"
local varlaby = real(reverse(substr(reverse("`varlab'"),1,2))) + 1900 //extract the last two digits in the label and add it by 1900
di "`varlaby'"
local varlabm = real(substr("`varlab'"),7,2) //extract the number after #.
//This command fails in the cases of make and rep78 and succeeds for price and mpg.
//I am looking for a general solution to this problem
di "`varlabm'"
}Thank you!
0 Response to Extract numbers (with varying lengths) from variable label
Post a Comment