Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Calculation standard deviation and skewness of a string of numbers. Converting a variable into a string.


From   XandeR XandeR <xanderx@mail.ru>
To   statalist@hsphsun2.harvard.edu
Subject   st: Calculation standard deviation and skewness of a string of numbers. Converting a variable into a string.
Date   Tue, 19 Aug 2008 18:41:01 +0400

Hello.
This is my first post and I am new to STATA.
 I have written a combinatorics program that takes values of a string and then generates all the possible outcomes of taking out three elements.
I am interested in mean, standard deviation and skewness of those lines. I have managed for it to calculate the mean, but don't know how to make STATA to calculate standard deviation and skewness of a list of numeric values.
Also I would like this program to make these calculations for a variable that already contains a string of numbers to input to the program.
Could you guys help me with these. The text of my program follows.
Thank you very much in advance

capture program drop tuples3
program define tuples3, rclass
                tempvar  j h i i1 i2 k k1 k2 m temp temp1
                local temp "`0'"
                *di as gr "temp is `temp'"
                                local k= wordcount("`temp'")
                                local l=comb(`k',3)
                                local k2=`k'-2
                                local k1=`k'-1
                                local m=1
                di as gr "There are " in ye "`k' " in gr "variables in the list"
                di as gr "There are " in ye "`l' " in gr "ways to choose " in ye "3 " in gr "items from the list of " in ye "`k'"

tokenize "`temp'", parse(" ")

forval i=1/`k2' {
                local i1=`i'+1

                forval j=`i1'/`k1' {
                                local i2=`j'+1

                                forval h=`i2'/`k' {
                                                local temp1 = itrim(subinstr("`temp'","``i''","",1))
                                                local temp1 = itrim(subinstr("`temp1'","``j''","",1))
                                                local temp1 = itrim(subinstr("`temp1'","``h''","",1))
                local t`m' = "`temp1'"
                local m=`m'+1
                                }
                }
}
                local m=`m'-1
local a= wordcount("`t1'")

*CALCULATING MEAN OF A TUPLE
forval j=1/`m' {
local mean1`j'=0
tokenize "`t`j''", parse(" ")
forval i=1/`a' {
local mean1`j'=`mean1`j''+real("``i''")
*local stdev1`j' = `stdev`j'' + (real("``i''")-`mean1`j'')^2
*error "unknown function +()
}
local mean1`j'=`mean1`j''/`a'
*local stdev1`j'=sqrt(`stdev1`j''/`a')

di in gr "t`j'" _col(5) " =  " in ye "`t`j''" in gr " with mean of" in ye " `mean1`j''" 
*in gr " and stdev" in ye " `stdev1`j''"
}
end

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index