0
私はStataデータセットのリストを持っています:ある変数の中にはtor
がありません。Stataファイルのリスト内で変数の名前を変更して作成する
データセットは何か(例えばAclass
、lclass
、等)であり得るclass
X Xと呼ばれる変数を含みます。私はrename
にそれらの変数dec
にしたいと思います。
変数adjusted
は、ファイル名にadjusted
と含まれていない場合は"no"
が含まれている場合は、"yes"
です。
Loop through list of datasets and their variables {
if variable contains pattern class
rename to dec
if no variable tor, then
gen str tor = total
if file name contains pattern adjusted
gen str adjusted = yes
else gen str adjusted = no
}
しかし、その後、適切なStataの言語で:
は、私はそれはのようになりますね。
は、だから私は今、これを持っているが、それは働いていない、それは何もしません...
cd "C:\Users\test"
local filelist: dir "." files "*.dta", respectcase
foreach filename of local myfilelist {
ds *class
local found `r(varlist)'
local nfound : word count `found'
if `nfound' == 1 {
rename `found' dec
}
else if `nfound' > 1 {
di as err "warning: multiple *class variables in `filename'"
}
capture confirm var tor
if !_rc == 0 {
gen tor = "total"
}
gen adjusted = cond(strpos("`filename'", "_adjusted_"), "yes", "no")
}
これらの回答を保存して読み込む方法については、[類似の質問](http://stackoverflow.com/questions/37845840/parsing-through-all-folders-in-a-directory)をご覧ください。ファイル名。 – lmo
ローカルの 'myfilelist'は定義されていないので、ループは何もしません。 'filelist'でなければなりません。 –