Dear members
I am trying hard to code a program that than boostrap descriptives (mean and CV) in ekstreme groups of a sample of GPs, se below. I want to be able to include more than one descriptive variable in each of these extreme groups in the program in the same boostrap-procedure. The draft-program below is able to to include to variables (auto dataset), calculate means and CVs in each of the groups for price and weight from the data set - and be included in the boostrap command. However, the program in not very smart and when I change the order of the variables from "myprogram price weight" to "myprogram weight price" there is a problem. I am new to this kind of programming. Hope someone can help?
All the best
Troels
*nyeste version 101021
clear *
cls
set seed 17
sysuse auto
cap progam drop myprog
program define myprog, rclass
version 17
args v y
marksample touse
* tempnames of scalar are defined
tempname p10 p10_mean p10_sd p10_cv ///
p90 p90_mean p90_sd p90_cv ///
yp10_mean yp10_sd yp10_cv ///
yp90_mean yp90_sd yp90_cv ///
qui summ `v' if `touse', detail
scalar `p10' = r(p10)
scalar `p90' = r(p90)
*return scalar N = r(N)
return scalar p10 = `p10'
return scalar p90 = `p90'
qui summ `v' if `touse' & inrange(`v', ., `p10'), detail
scalar `p10_mean' = r(mean)
scalar `p10_sd' = r(sd)
scalar `p10_cv' = `p10_sd' / `p10_mean'
*return scalar p10_N = r(N)
return scalar p10_mean = `p10_mean'
return scalar p10_sd = `p10_sd'
return scalar p10_cv = `p10_cv'
qui summ `v' if `touse' & inrange(`v', `p90', .), detail
scalar `p90_mean' = r(mean)
scalar `p90_sd' = r(sd)
scalar `p90_cv' = `p90_sd' / `p90_mean'
*return scalar p90_N = r(N)
return scalar p90_mean = `p90_mean'
return scalar p90_sd = `p90_sd'
return scalar p90_cv = `p90_cv'
*****
qui summ `y' if `touse' & inrange(`y', ., `p10'), detail
scalar `yp10_mean' = r(mean)
scalar `yp10_sd' = r(sd)
scalar `yp10_cv' = `yp10_sd' / `yp10_mean'
*return scalar yp10_N = r(N)
return scalar yp10_mean = `yp10_mean'
return scalar yp10_sd = `yp10_sd'
return scalar yp10_cv = `yp10_cv'
qui summ `y' if `touse' & inrange(`y', `p90', .), detail
scalar `yp90_mean' = r(mean)
scalar `yp90_sd' = r(sd)
scalar `yp90_cv' = `yp90_sd' / `yp90_mean'
*return scalar yp90_N = r(N)
return scalar yp90_mean = `yp90_mean'
return scalar yp90_sd = `yp90_sd'
return scalar yp90_cv = `yp90_cv'
end
myprog price weight
ret list
bootstrap p10_mean=r(p10_mean) p90_mean=r(p90_mean) p10_cv=r(p10_cv) p90_cv=r(p90_cv) yp10_mean=r(yp10_mean) yp10_cv=r(yp10_cv), reps(1000):myprog price weight
0 Response to Bootstrapping more descriptive of more than one variable in extreme groups of a sample - how to code/program in a smart way?
Post a Comment