Dear Statalisters,
I wish to write a simple optimisation problem to find the optimal fractional power for which the skewness of the targeted variable will be minimized (go to zero). I am aware of the commands lnskew0 and bcskew0. My question, although related to the idea of Tukey's ladder of powers, is more fundamental and related to the optimize code. Here is my code and output:
mata :
: void skew0(todo,p,y,g,H)
> {
> real vector X, Xp, d
> real scalar s
>
> X = st_data(.,"var1")
> Xp = X :^p
>
> d = Xp :-mean(Xp)
> y = mean(d:^3) / (mean(d:^2)):^(3/2)
> }
note: argument todo unused
note: argument g unused
note: argument H unused
note: variable s unused
: S = optimize_init()
: optimize_init_which(S,"min")
: optimize_init_evaluator(S, &skew0())
: optimize_init_technique(S,"nr")
: optimize_init_params(S,1)
: p = optimize(S)
Iteration 0: f(p) = 3.2341254
Iteration 1: f(p) = 3.0366119
Iteration 2: f(p) = .92755502 (not concave)
Iteration 3: f(p) = -.45619791 (not concave)
Iteration 4: f(p) = -.46533213
Iteration 5: f(p) = -.47138751 (not concave)
Iteration 6: f(p) = -.47154085 (not concave)
Iteration 7: f(p) = -.4715562
Iteration 8: f(p) = -.47155913 (not concave)
Iteration 9: f(p) = -.47155979
: printf("%12.8f",p) // iteration 0 gives the initial skewness of variable hin
0.00000004
: end
I know that the calculation of skewness works because iteration 0 gives the correct initial skewness of variable "var1" shown above at 3.2341254. However, I also know that the optimal value of p at 0.00000004 is incorrect as the skewness flips into negative and converges to -.47155979. I also know from other work that this power should be about 0.10.
Could someone more experienced that myself look at this code and help me understand what I am doing wrong.
many thanks in advance, Demetris Christodoulou
Related Posts with optimize: set skewness to zero
Time-to-event analysis for panels STATA 13Hi all, I have the following database Code: * Example generated by -dataex-. To install: ssc inst…
Storing decile values correspong to decile rank in a separate variableHi everyone, I am writing to understand how I can store the decile values for the following dummy d…
Estimate Cohen´s (d) for within-subjects?Dear all, Which is the right formula for Cohen´s (d) for within-subjects? There are many formulas a…
error occurred while loading xtsur.ado Dear All, Greetings I use stata 14.1. I try to execute xtsur command . sometimes I get the result b…
How to find mean in a specific range.How can I find the mean value of “urban” variable from state “Alabama” to “Massachusetts”. What will…
Subscribe to:
Post Comments (Atom)
0 Response to optimize: set skewness to zero
Post a Comment