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
Generate a variableHello, I use Stata for the empirical part of my bachelor thesis and have not used Stata before so I…
Combined plots with no marginHi, I would like to combine 3 plots with no margin (or as little as possible) and 1 unique legend t…
Do I need to cluster the standard errors?Dear all, I have a panel data set of a study where 69 individuals were observed over 8 points in tim…
Binary DV with reghdfe with too many negative predictionsHi Everyone, I want to run a probability model by using high-dimensional fixed effects to understan…
Row total conditional on age restrictionDear Statalist members B8_01 stands for the age of the youngest child, B8_02 stands for his/her old…
Subscribe to:
Post Comments (Atom)
0 Response to optimize: set skewness to zero
Post a Comment