Hi,
I'm still new to Stata and am having some trouble following some code that looks as follows. I've included my interpretation in a step by step manner below and hope that you can let me know if I've understood it properly.
From what I can gather, this loop generates begin and end for every i at an absolute interval of 10, between the 1st and 99th percentiles of mass.
At each iteration of the loop, Stata replaces smooth with i if mass falls within the current interval (i - i+10).
So for example if i=50 and mass=53, smooth would be replaced by i=50. This also holds for mass=60, right?
Effectively this means that at i=50, observations for mass=51 to mass=60 will receive smooth=50, correct?
This is close to, but not exactly the same as, rounding down to the nearest 10, yes?
Is there a statistical term for this type of smoothing, (e.g. smoothing by rounding down)?
Thanks, I look forward to your feedback.
I'm still new to Stata and am having some trouble following some code that looks as follows. I've included my interpretation in a step by step manner below and hope that you can let me know if I've understood it properly.
Code:
gen smooth = 0 quietly summarize mass scalar p1 = r(p1) scalar p99 = r(p99) scalar interval = 10 forvalues i = `=scalar(p1)'(`=scalar(interval)')`=scalar(p99)' { scalar begin = `i' scalar end = `i'+`=scalar(interval)' if `i' == `=scalar(p1)' {replace smooth = `i' if mass <= `=scalar(end)'} else {replace smooth = `i' if mass> `=scalar(begin)' & mass <= `=scalar(end)'} }
At each iteration of the loop, Stata replaces smooth with i if mass falls within the current interval (i - i+10).
So for example if i=50 and mass=53, smooth would be replaced by i=50. This also holds for mass=60, right?
Effectively this means that at i=50, observations for mass=51 to mass=60 will receive smooth=50, correct?
This is close to, but not exactly the same as, rounding down to the nearest 10, yes?
Is there a statistical term for this type of smoothing, (e.g. smoothing by rounding down)?
Thanks, I look forward to your feedback.
Comment