Hi,
My first time posting on this forum. I am using Stata 14.
I am trying to create a variable which has the percentile value for the value of a given variable. For example, if the 10th percentile has a value of 15.5 then all temperatures less than 20.2 are reflected as 20.2. Similarly for temperatures between 20.2 and 23.2 are then reflected as 23.2. I intend to include this variable (along with others) in a table.
The code I have been using (unsuccessfully) follows.
sysuse citytemp4
pctile jan_perc = tempjan, nq(10)
levelsof jan_perc
* This gives values for the different percentiles.
gen jan_var = 0
forvalues i of jan_perc {
replace jan_var = `i' if tempjan > `i'
}
I get an error message r(198)
Any help on this simple issue would be much appreciated.
Thanks,
My first time posting on this forum. I am using Stata 14.
I am trying to create a variable which has the percentile value for the value of a given variable. For example, if the 10th percentile has a value of 15.5 then all temperatures less than 20.2 are reflected as 20.2. Similarly for temperatures between 20.2 and 23.2 are then reflected as 23.2. I intend to include this variable (along with others) in a table.
The code I have been using (unsuccessfully) follows.
sysuse citytemp4
pctile jan_perc = tempjan, nq(10)
levelsof jan_perc
* This gives values for the different percentiles.
gen jan_var = 0
forvalues i of jan_perc {
replace jan_var = `i' if tempjan > `i'
}
I get an error message r(198)
Any help on this simple issue would be much appreciated.
Thanks,
Comment