I have a question with regards to descriptive statistics. I have been working on a code to get the sum output of my variables of interest in one table at the same time however as some of the variables are not continuous variables I would like to have them expressed in percentages. Would be great if you could have a quick look in what I have done so far!
Code:
//4. List variables for which you'd like to report summary statistics local age_1 ownsphone school schoolagedchildren_1 childrenattendschool partner childmortality //5. Create an empty matrix y with J rows and K columns based on the number of variables of interest and // the number of summary statistic scalars that you wish to report local j_rows=7 local k_columns=4 mat m = J(`j_rows',`k_columns',.) //6. Initialize counter variable y to start at 1 local y=1 //7. Generate matrix of summary statistics fromt he pre-specified list of variables foreach var of varlist age_1 ownsphone school schoolagedchildren_1 childrenattendschool partner childmortality { sum `var' if round==0, d mat m[`y',1] = round(r(mean),.1) sum `var' if round==0, d mat m[`y',2] = round(r(sd),.1) sum `var' if round==100, d mat m[`y',3] = round(r(mean),.1) sum `var' if round==100, d mat m[`y',4] = round(r(sd),.1) local y=`y'+1 } //8. Name Columns and Rows mat colnames m = "Control Mean" "Control SD" "Treatment Mean" "Treatment SD" mat rownames m = "age_1" "ownsphone" "school" "schoolagedchildren_1" "childrenattendschool" "partner" "childmortality" //9. Save matrix to spreadsheet mat2txt, matrix(m) saving (FILE LOCATION) replace
Linda
0 Response to Descriptive statistics: add percentages to summary statistics (matrix)
Post a Comment