본문 바로가기

[STATA] 히스토그램과 instant command - histogram, scatteri 하나의 STATA do-file 일부를 살펴보면서 histogram, twoway histogram, scatteri command 등에 대해 알아보겠습니다. twoway (histogram foreign, discrete width(5) percent ytitle(percent of sites) ///xtitle("foreigners") xlabel(, angle(zero) tposition(inside)) ///title("Distribution of percent of foreigners")) ///(scatteri 0 13 25 13, c(l) m(i) legend(off) ///note("Note: Red line is the average (13).")) save "`figurepath'dis.. 더보기
[STATA] 정말 유용한 egen row: mean, sum, total, max, min, tag, group, concat, cut egen command를 통해 활용할 수 있는 함수들을 몇 가지 알아보겠습니다. mean() egen mean_price = mean(price), by(store_id) 이는 각각의 store_id에 대하여 price의 평균값을 mean_price라는 새로운 변수로 저장합니다. 예컨대 각각의 store 물건 가격의 평균값이라고 할 수 있지요.이때, 관측치에 결측값이 있으면 mean을 구하지 못합니다. rowmean() . egen avg = rowmean(a_score b_score c_score) 이는 각각의 관측값에서 서로 다른 변수 a_score,b_score,c_score 간의 평균값을 계산해서 새로운 변수로 저장합니다. 예컨대 a,b,c가 수학, 과학, 영어 점수일 때, 전과목의 평균치를 구할.. 더보기
[STATA] 관측치 고유성/중복 확인 - isid isid command는 각각의 변수들이 고유한 관측치들을 나타내는지를 확인하는 데에 쓰입니다. . isid mpg 그런데 variable mpg does not uniquely identify the observations r(459); 와 같은 결과가 나타났다면 동일한 mpg가 있다는 겁니다. 동일한 관측치가 나타난 것을 안다면 이를 확인하는 법은 _N를 통해 살펴보았었죠. .sort mpg.by mpg: generate nobs = _N.list make mpg if nobs >1, sepby(mpg) 하나의 예시를 더 살펴볼까요. 패널데이터에서 두 개의 관측치가 중복적으로 입력되었을 수 있겠죠. 이를 확인하기 위해 다음과 같은 command를 실행합니다. . isid company year 아무 .. 더보기