문제 설명
문자를 포함하는 고유 식별자와 함께 xtreg 사용 (Using xtreg with unique identifier that includes letters)
내 패널 데이터 세트로 회귀를 실행하려고 합니다.
상태 고정 효과를 설명하고 약간 이상한 식별자로 작업하려고 합니다.
내 분석 단위는 유틸리티 ID와 state로 구성된 복합 고유 식별자를 생성한 상태의 유틸리티입니다.
따라서 내 데이터는 다음과 같습니다.
unique_id ownership amiratio popd
10570AL REC .45 3430
4032CA IOU .85 4350
그러나 xtset
은(는) 식별자의 문자를 좋아하지 않습니다.
내가 의도한 회귀는 아래와 같습니다.
6xtreg amiratio ownership ownership#popd, fe vce(cluster i.state)
어떻게 해야 하나요? 이 회귀를 실행하기 위해 내 고유 ID를 올바른 형식으로 가져오시겠습니까?
참조 솔루션
방법 1:
The encode
command can be used for this purpose:
clear
input str10 unique_id str3 ownership amiratio popd
10570AL REC .45 3430
4032CA IOU .85 4350
end
encode unique_id, generate(wanted)
This converts a string variable to numeric with value labels matching the strings:
list unique_id wanted, abbreviate(10)
+‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑+
| unique_id wanted |
|‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑|
1. | 10570AL 10570AL |
2. | 4032CA 4032CA |
+‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑+
list unique_id wanted, abbreviate(10) nolabel
+‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑+
| unique_id wanted |
|‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑|
1. | 10570AL 1 |
2. | 4032CA 2 |
+‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑+
Using xtset
with wanted
will work in contrast with unique_id
:
xtset unique_id
string variables not allowed in varlist;
unique_id is a string variable
r(109);
xtset wanted
panel variable: wanted (balanced)
(by GentilmanMyles、user8682794)