STATA 遍历变量名 标签内容 变量值

sysuse auto,clear
levelsof foreign ,local(levels)
foreach x of local levels {
 di in yellow "`x' is a unique value of rep78"
}

//遍历各个变量的标签及变量值
sysuse auto.dta,clear
local k=_N
foreach var of varlist _all{
    local a:var label `var'
    disp "`a'"
    forvalues i=1/`k'{
        disp `var'[`i']
    }
}


//遍历各个变量的标签
sysuse auto.dta,clear
local k=_N
foreach var of varlist _all{
    local a:var label `var'
    disp "`a'"
}
//遍历各个变量名
sysuse auto.dta,clear
local k=_N
foreach var of varlist _all{
    disp "`var'"
}
//遍历各个变量名
ds
foreach v of varlist  `r(varlist)'  {
    dis "`v'"
}

 

posted @ 2023-04-18 09:13  myrj  阅读(210)  评论(0编辑  收藏  举报