I am trying to make a table of normalized differences (based on Imbens and Rubin (2015)) between two definitions of income groups in my data. Here is an example dataset:
This is my code:
I am using Stata 17. The program works fine but I get an error in the table command saying "command normdiff exited with an error when run using the entire sample". I am unable to figure out what is causing the error.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(inc_status_1 inc_status_2 weight) byte raedyrs 1 1 7696 10 1 1 7696 10 1 1 7696 10 1 1 7696 10 1 1 7696 10 1 1 7696 10 1 1 7696 10 1 1 7696 10 1 1 7696 10 1 1 7696 10 1 1 7696 10 1 1 7696 10 1 1 7696 10 1 1 7696 10 1 1 7696 10 1 1 12696 9 1 1 12696 9 1 1 12696 9 1 1 12696 9 1 1 12696 9 1 1 12696 9 1 1 12696 9 1 1 12696 9 1 1 12696 9 1 1 12696 9 1 1 12696 9 1 1 12696 9 1 1 12696 9 1 1 12696 9 1 1 12696 9 1 1 7361 10 1 1 7361 10 1 1 7361 10 1 1 7361 10 1 1 7361 10 1 1 7361 10 1 1 7361 10 1 1 7361 10 1 1 7361 10 1 1 7361 10 1 1 7361 10 1 1 7361 10 1 1 7361 10 1 1 7361 10 1 1 7361 10 1 1 0 10 1 1 0 10 1 1 0 10 1 1 0 10 1 1 0 10 1 1 0 10 1 1 0 10 1 1 0 10 1 1 0 10 1 1 0 10 1 1 0 10 1 1 0 10 1 1 0 10 1 1 0 10 1 1 0 10 1 1 6930 12 1 1 6930 12 1 1 6930 12 1 1 6930 12 1 1 6930 12 1 1 6930 12 1 1 6930 12 1 1 6930 12 1 1 6930 12 1 1 6930 12 1 1 6930 12 1 1 6930 12 1 1 6930 12 1 1 6930 12 1 1 6930 12 1 1 3364 14 1 1 3364 14 1 1 3364 14 1 1 3364 14 1 1 3364 14 1 1 3364 14 1 1 3364 14 1 1 3364 14 1 1 3364 14 1 1 3364 14 1 1 3364 14 1 1 3364 14 1 1 3364 14 1 1 3364 14 1 1 3364 14 1 1 10986 14 1 1 10986 14 1 1 10986 14 1 1 10986 14 1 1 10986 14 1 1 10986 14 1 1 10986 14 1 1 10986 14 1 1 10986 14 1 1 10986 14 end label values inc_status_1 inc_status_1 label values inc_status_2 inc_status_1 label def inc_status_1 1 "Yes", modify label values raedyrs EDYRS
Code:
ssc install _gwtmean, replace cap program drop normdiff program define normdiff, rclass syntax varlist(min=1 max=1) cap drop mean1 cap drop mean1_1 cap drop m_mean1 cap drop mean2 cap drop mean2_1 cap drop m_mean2 cap drop std1 cap drop std2 cap drop std1sq cap drop std2sq cap drop ndiff cap drop std cap drop m_std1 cap drop m_std2 qui egen double mean1 = wtmean(`1'), weight(weight) by(inc_status_1) qui gen mean1_1 = mean1 if inc_status_1==1 qui egen m_mean1 = max(mean1_1) qui egen double mean2 = wtmean(`1'), weight(weight) by(inc_status_2) qui gen mean2_1 = mean2 if inc_status_2==1 qui egen m_mean2 = max(mean2_1) qui egen std1=sd(`1') if inc_status_1==1 qui gen std1sq=std1^2 qui egen m_std1=max(std1sq) qui egen std2=sd(`1') if inc_status_2==1 qui gen std2sq=std2^2 qui egen m_std2=max(std2sq) qui gen std = sqrt((m_std1+m_std2)/2) qui gen ndiff=(m_mean1-m_mean2)/std format ndiff %20.10f qui sum ndiff local normdiff = r(mean) return local normdiff `normdiff' dis "The normalized difference is" %20.10f ndiff end normdiff raedyrs table (command) (result), /// command(Diff = ( r(normdiff)) : /// normdiff raedyrs)
Comment