0
summarize X , detail  

gen un_p5 = di r(p5) 
gen un_p10 = di r(p10) 
gen un_p25 = di r(p25)
gen un_p50 = di r(p50) 
gen un_p75 = di r(p75) 
gen un_p90 = di r(p90) 
gen un_p95 = di r(p95) 
gen un_p99 = di r(p99)

I want to summarize, detail another variable Y in order to ttest whether the percentiles of both variables (X, Y) are equal

summarize Y, detail 

gen c_p5 = di r(p5) 
gen c_p10 = di r(p10) 
gen c_p25 = di r(p25)
gen c_p50 = di r(p50) 
gen c_p75 = di r(p75) 
gen c_p90 = di r(p90) 
gen c_p95 = di r(p95) 
gen c_p99 = di r(p99)

I get this error when using gen command to create a variable

di not found 
r(111) ;

I want to ttest un_p5 = c_p5

  un_p10 = c_p10 

for each percentile-.

Nick Cox
  • 35,529
  • 6
  • 31
  • 47
user123456
  • 67
  • 1
  • 1
  • 10
  • Each pair of quantiles is just one data point, so the _t_ test intended sounds meaningless: neither "variable" is a variable. Even if you bundle all those quantiles together, they are not mutually independent and using 8 of them is arbitrary. To compare distributions, start with a quantile-quantile plot. These are statistical issues to be raised with local advisors and/or a statistical forum. – Nick Cox Feb 06 '18 at 14:41
  • You have comments and an answer. Whether they are or are not what you want, you shouldn't ignore them. – Nick Cox Feb 12 '18 at 14:32

1 Answers1

0

Just omit di: it is here irrelevant as well as illegal. The pattern you are seeking is

gen un_p5 = r(p5) 

Note that you need summarize, detail for this to be useful. (With summarize alone, the above statement is legal, but will just store numeric missing in every observation.)

But why you are putting 8 constants in 8 variables is unclear. Those constants will be repeated in every observation. Why not use scalars instead, or a vector? What do you want to do here?

Nick Cox
  • 35,529
  • 6
  • 31
  • 47
  • The questions in the last paragraph are addressed in an edit. My comment on the question makes some statistical remarks. – Nick Cox Feb 06 '18 at 14:42