Dear All,
I am trying to make a table containing :
a) the name of the variables and its subcategories
b) the proportion of observations of each variables (for categorical variables) or the mean (for continuous variables)
c) the p-values of the chi2 test (for categorical variables) or ttest (for continuous variables)
I have tried to modify a bit the commands provide by Nick Cox here without success.
Here my command:
I would like to be able to construct a table like this. I post a small sample in case someone is willing to help.
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte gender float age_manager byte q5_1_7 float(potential_suc crops farm_typology farm_size dep_var1 WTU)
0 32 3 1 20 2 3 3 1
0 38 4 0 0 3 3 2 1
0 36 4 0 11 4 1 2 1
0 22 1 0 2 2 1 3 1
0 53 3 0 5.5 4 3 2 1
0 46 3 0 9 4 3 1 1
0 30 4 0 2 2 2 2 1
0 25 1 0 3 2 2 3 1
0 21 3 1 34 4 3 3 1
0 27 3 0 0 4 2 2 1
0 27 4 1 141 3 4 1 1
0 31 4 2 101 4 4 3 0
0 28 2 1 44 4 3 3 0
0 35 4 1 131 2 4 2 0
0 28 3 0 15 2 2 3 1
0 25 3 1 0 4 3 3 0
0 26 3 0 8 1 3 2 0
0 31 1 0 4 4 2 3 1
0 25 4 0 6 2 2 3 1
0 49 3 0 0 4 4 3 1
0 28 1 1 4 4 2 2 0
0 24 4 2 4 2 3 3 0
1 45 4 0 2 4 3 2 1
1 24 4 1 4 4 2 3 0
1 30 4 0 2 4 2 3 1
1 18 1 0 5 4 3 3 0
1 42 4 0 4 4 3 2 0
0 30 4 1 83 4 3 3 1
0 37 4 0 10 2 3 2 1
0 31 3 1 0 2 3 3 0
0 29 4 1 102 4 3 2 0
0 27 4 0 0 4 1 3 0
0 32 2 0 0 3 3 3 0
0 34 4 0 44 3 4 3 0
0 27 3 0 10 4 2 3 1
0 16 1 0 6 4 2 1 1
0 27 1 0 3 4 3 1 0
1 29 3 0 3 4 1 3 0
1 31 4 0 0 4 1 3 0
0 18 4 0 23 3 3 1 1
0 39 3 0 0 4 4 1 1
0 23 3 0 2 2 3 3 1
0 28 4 0 1 2 3 2 0
0 22 4 1 0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ender gender
label def gender 0 "Male", modify
label def gender 1 "Female", modify
label values q5_1_7 q5_1_7
label def q5_1_7 1 "elementary school", modify
label def q5_1_7 2 "middle school", modify
label def q5_1_7 3 "technical school (2-3 years)", modify
label def q5_1_7 4 "high school", modify
label def q5_1_7 5 "university degree and higher", modify
label values farm_typology farm_typology
label def farm_typology 1 "Innovator", modify
label def farm_typology 2 "Diversifier", modify
label def farm_typology 3 "Environmentalist", modify
label def farm_typology 4 "Traditionalist", modify
label values farm_size farmsize
label def farmsize 1 "Small farms: EUR 2 000 – < EUR 8 000", modify
label def farmsize 2 "Medium-sized farms: EUR 8 000 – < EUR 25 000", modify
label def farmsize 3 "Large farms: EUR 25 000 – < EUR 100 000", modify
label def farmsize 4 "Very large farms: ≥ EUR 100 000", modify
label values dep_var1 dep_var1
label def dep_var1 1 "No, dot' know", modify
label def dep_var1 2 "Yes, conditional to successors", modify
label def dep_var1 3 "Yes, no conditional to successor", modify
label values WTU WTU
label def WTU 0 "Induced WTU", modify
label def WTU 1 "Spontaneous WTU", modify
------------------ copy up to and including the previous line ------------------
thanks
Federica
I am trying to make a table containing :
a) the name of the variables and its subcategories
b) the proportion of observations of each variables (for categorical variables) or the mean (for continuous variables)
c) the p-values of the chi2 test (for categorical variables) or ttest (for continuous variables)
I have tried to modify a bit the commands provide by Nick Cox here without success.
Here my command:
Code:
local Xcat gender q5_1_7 potential_suc farm_typology farm_size local Zcon age_ crops local Y dep_var1 WTU gen Xnamecat = "" gen Xnamecatsub = "" gen Xnamecon = "" gen Xnameconsub = "" gen Yname = "" gen double chi2 = . gen double pvalchi2 = . gen double mu_1= . gen double mu_2= . gen double pvalttest = . gen cols = . local i = 1 foreach x of local Xcat { foreach z of local Zcon { foreach y of local Y { tab `x' `y', col chi2 ttest `z', by( `y') unequal quietly { replace Xnamecat= "`x'" in `i' replace Xnamecatsub= "`x'" in `i' here i would like the label of the different categories in each variable replace Xnamecon= "`x'" in `i' replace Xnameconsub= "`x'" in `i' here i would like the label of the different categories in each variable replace Yname = "`y'" in `i' it would be nice to have this at the top of the table replace chi2 = r(chi2) in `i' for the chi2 test replace pvalchi2= r(p) in `i' replace mu_1= r(mu_1) in `i' this i would like to appear in coloumn replace mu_2= r(mu_2) in `i' this i would like to appear in coloumn replace pvalttest= r(p) in `i' this i am not sure it reports the p-values of ttest replace cols = r(c) in `i' here I would like the percentage or mean values of the different variable but tab does not store th } local ++i } } } list Xname-cols
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte gender float age_manager byte q5_1_7 float(potential_suc crops farm_typology farm_size dep_var1 WTU)
0 32 3 1 20 2 3 3 1
0 38 4 0 0 3 3 2 1
0 36 4 0 11 4 1 2 1
0 22 1 0 2 2 1 3 1
0 53 3 0 5.5 4 3 2 1
0 46 3 0 9 4 3 1 1
0 30 4 0 2 2 2 2 1
0 25 1 0 3 2 2 3 1
0 21 3 1 34 4 3 3 1
0 27 3 0 0 4 2 2 1
0 27 4 1 141 3 4 1 1
0 31 4 2 101 4 4 3 0
0 28 2 1 44 4 3 3 0
0 35 4 1 131 2 4 2 0
0 28 3 0 15 2 2 3 1
0 25 3 1 0 4 3 3 0
0 26 3 0 8 1 3 2 0
0 31 1 0 4 4 2 3 1
0 25 4 0 6 2 2 3 1
0 49 3 0 0 4 4 3 1
0 28 1 1 4 4 2 2 0
0 24 4 2 4 2 3 3 0
1 45 4 0 2 4 3 2 1
1 24 4 1 4 4 2 3 0
1 30 4 0 2 4 2 3 1
1 18 1 0 5 4 3 3 0
1 42 4 0 4 4 3 2 0
0 30 4 1 83 4 3 3 1
0 37 4 0 10 2 3 2 1
0 31 3 1 0 2 3 3 0
0 29 4 1 102 4 3 2 0
0 27 4 0 0 4 1 3 0
0 32 2 0 0 3 3 3 0
0 34 4 0 44 3 4 3 0
0 27 3 0 10 4 2 3 1
0 16 1 0 6 4 2 1 1
0 27 1 0 3 4 3 1 0
1 29 3 0 3 4 1 3 0
1 31 4 0 0 4 1 3 0
0 18 4 0 23 3 3 1 1
0 39 3 0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 4 0 2 4 2 3 0
0 30 3 0 6 4 3 2 1
0 26 4 1 9 4 3 3 1
end
label values gender gender
label def gender 0 "Male", modify
label def gender 1 "Female", modify
label values q5_1_7 q5_1_7
label def q5_1_7 1 "elementary school", modify
label def q5_1_7 2 "middle school", modify
label def q5_1_7 3 "technical school (2-3 years)", modify
label def q5_1_7 4 "high school", modify
label def q5_1_7 5 "university degree and higher", modify
label values farm_typology farm_typology
label def farm_typology 1 "Innovator", modify
label def farm_typology 2 "Diversifier", modify
label def farm_typology 3 "Environmentalist", modify
label def farm_typology 4 "Traditionalist", modify
label values farm_size farmsize
label def farmsize 1 "Small farms: EUR 2 000 – < EUR 8 000", modify
label def farmsize 2 "Medium-sized farms: EUR 8 000 – < EUR 25 000", modify
label def farmsize 3 "Large farms: EUR 25 000 – < EUR 100 000", modify
label def farmsize 4 "Very large farms: ≥ EUR 100 000", modify
label values dep_var1 dep_var1
label def dep_var1 1 "No, dot' know", modify
label def dep_var1 2 "Yes, conditional to successors", modify
label def dep_var1 3 "Yes, no conditional to successor", modify
label values WTU WTU
label def WTU 0 "Induced WTU", modify
label def WTU 1 "Spontaneous WTU", modify
------------------ copy up to and including the previous line ------------------
thanks
Federica
Comment