いくつかの国にまたがるデータのパネル (企業年数) があります。logit
国ごとに、最初の 5 年間を使用してモデルを推定し、このモデルを使用してpredict
、その後の数年間の確率を計算します。私foreach
は国をforvalues
ループし、その後の年をループします。
最初の数カ国は (推定と予測の両方で) うまく機能しますが、5 番目の国の最初の標本外予測は次のように失敗します。
Country: United Kingdom
Year: 1994
too many variables specified
r(103);
モデルは適合し、1994 年には確率を予測するのに十分なデータがあります。私のpredict
電話は:
predict temp_`c'`y' ///
if (country == "`c'") ///
& (fyear == `y'), ///
pr
このエラーの原因は何ですか? 同じループの他の場所で作業しているためlogit
、私は混乱しています。predict
ありがとう!
FWIW、これが .do ファイルです。
* generate table 5 from Denis and Osobov (2008 JFE)
preserve
* loop to estimate model by country
levelsof country, local(countries)
foreach c of local countries {
display "Country: `c'"
summarize fyear if (country == "`c'"), meanonly
local est_low = `r(min)'
local est_high = `=`r(min)' + 4'
local pred_low = `=`r(min)' + 5'
local pred_high = `r(max)'
logit payer size v_a_tr e_a_tr re_be_tr ///
if (country == "`c'") ///
& inrange(fyear, `est_low', `est_high')
forvalues y = `pred_low'/`pred_high' {
display "Country: `c'"
display "Year: `y'"
predict temp_`c'`y' ///
if (country == "`c'") ///
& (fyear == `y'), ///
pr
}
}
* combine fitted values and generate delta
egen payer_expected = rowfirst(temp_*)
drop temp_*
generate delta = payer - payer_expected
* table
table country fyear, ///
contents(count payer mean payer mean payer_expected)
*
restore
更新: Idrop (country == "United Kingdom")
の場合、同じ問題が米国 (パネルの次と最後の国) に移行します。Idrop inlist(country, "United Kingdom", "United States")
の場合、問題はなくなり、.do ファイルが実行されます。