楼主: 经济人生
8770 9

如何计算log variance? [推广有奖]

  • 28关注
  • 8粉丝

已卖:571份资源

博士生

18%

还不是VIP/贵宾

-

威望
0
论坛币
29409 个
通用积分
2.6392
学术水平
32 点
热心指数
31 点
信用等级
25 点
经验
4957 点
帖子
163
精华
0
在线时间
250 小时
注册时间
2004-12-31
最后登录
2025-12-17

楼主
经济人生 发表于 2007-10-15 20:34:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

我现在要进行如下计算: 分年龄分年计算几个指标的log variance

但现在的问题是,没有一个Variance 函数。只有采用sum命令,然后再利用矩阵转换,才能声称上述指标。

应该不难的,但我对矩阵还一窍不通啊,哪位高手帮帮忙!(应该采用return list 或return list,我猜)

by age yr: sum hinc hinc1 hcon2 hcon1 hcon4

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:variance varian ance Log NCE Log variance

回帖推荐

arlionn 发表于2楼  查看完整内容

foreach var of varlist hinc hinc1 hcon2 hcon1 hcon4{  qui sum `var'  dis in y "log-var(`var') = " in g ln(r(sd)^2)}

蓝色 发表于4楼  查看完整内容

以下是引用经济人生在2007-10-15 21:45:00的发言:真的非常感谢楼上的。但是否有可能说说,这是什么意思?或者到什么地方能查到 这些都的慢慢积累,看的书多了就知道了。学什么软件,不是拿过就能想干什么就干什么的,必须的先把一些基础的看看。比如:stata的manual。http://www.pinggu.org/bbs/thread-188722-1-1.html&page=1http://www.pinggu.org/bbs/thread-188730-1-1.html&page=1

蓝色 发表于7楼  查看完整内容

foreach var of varlist hinc hinc1 hcon2 hcon1 hcon4{  by age yr: egen `var'sd=sd(`var')  gen  ln`var'sd=ln(`var'sd)  } [此贴子已经被作者于2007-10-17 22:58:21编辑过]

本帖被以下文库推荐

沙发
arlionn 在职认证  发表于 2007-10-15 21:06:00

foreach var of varlist hinc hinc1 hcon2 hcon1 hcon4{
  qui sum `var'
  dis in y "log-var(`var') = " in g ln(r(sd)^2)
}

已有 1 人评分论坛币 学术水平 热心指数 收起 理由
crystal8832 + 10 + 1 + 1 热心帮助其他会员

总评分: 论坛币 + 10  学术水平 + 1  热心指数 + 1   查看全部评分

藤椅
经济人生 发表于 2007-10-15 21:45:00

真的非常感谢楼上的。

但是否有可能说说,这是什么意思?或者到什么地方能查到

板凳
蓝色 发表于 2007-10-16 07:26:00
以下是引用经济人生在2007-10-15 21:45:00的发言:

真的非常感谢楼上的。

但是否有可能说说,这是什么意思?或者到什么地方能查到

这些都的慢慢积累,看的书多了就知道了。

学什么软件,不是拿过就能想干什么就干什么的,必须的先把一些基础的看看。

比如:stata的manual。

https://bbs.pinggu.org/thread-188722-1-1.html&page=1

https://bbs.pinggu.org/thread-188730-1-1.html&page=1

报纸
经济人生 发表于 2007-10-16 15:52:00

谢谢斑竹的提醒,你说的对。

其实我本来stata9的manual都复印了的,但现在因为不在自己学校,查资料很不方便,所以就想偷懒了。

没想到论坛上还有电子版的manual,谢谢啦!

地板
经济人生 发表于 2007-10-17 22:07:00

我还是没有办法求出来啊!

我要求按年龄按年代汇总求方差啊!

foreach可以解决我同时算好几个指标的问题,但解决不了按年龄按年代求解的问题。我只会BY啊,但by不能与foreach 放在一起用?

谁还知道?谢谢了阿!

7
蓝色 发表于 2007-10-17 22:24:00

foreach var of varlist hinc hinc1 hcon2 hcon1 hcon4{
  by age yr: egen `var'sd=sd(`var')

  gen  ln`var'sd=ln(`var'sd)
  }

[此贴子已经被作者于2007-10-17 22:58:21编辑过]

8
经济人生 发表于 2007-10-17 22:36:00
以下是引用蓝色在2007-10-17 22:24:00的发言:

foreach var of varlist hinc hinc1 hcon2 hcon1 hcon4{
  by age yr: egen `var'sd=sd(`var)   没有sd函数,还是要用sum感觉,估计是这里错了。

  gen  ln`var'sd=ln(`var'sd)
  }

9
蓝色 发表于 2007-10-17 22:59:00

少了一个引号

egen里面是有sd函数的

10
蓝色 发表于 2007-10-17 23:04:00


help egen                                                                                    dialog:  egen
----------------------------------------------------------------------------------------------------------

Title

    [D] egen -- Extensions to generate


Syntax

        egen [type] newvar = fcn(arguments) [if] [in] [, options]

    by may be used with some of the egen functions as noted below.

    where depending on the fcn, arguments refers to an expression, varlist, or numlist, and the options
        are also fcn dependent, and where fcn is

        anycount(varlist), values(integer numlist)
            may not be combined with by.  It returns the number of variables in varlist for which values
            are equal to any of the integer values in a supplied numlist.  Values for any observations
            excluded by either [if] or [in] are set to 0 (not missing).  Also see anyvalue(varname) and
            anymatch(varlist).

        anymatch(varlist), values(integer numlist)
            may not be combined with by.  It is 1 if any of the variables in varlist are equal to any of
            the integer values in a supplied numlist and 0 otherwise.  Values for any observations
            excluded by either [if] or [in] are set to 0 (not missing).  Also see anyvalue(varname) and
            anycount(varlist).

        anyvalue(varname), values(integer numlist)
            may not be combined with by.  It takes the value of varname if varname is equal to any of
            the integer values in a supplied numlist and is missing otherwise.  Also see
            anymatch(varlist) and anycount(varlist).

        concat(varlist) [, format(%fmt) decode maxlength(#) punct(pchars)]
            may not be combined with by.  It concatenates varlist to produce a string variable.  Values
            of string variables are unchanged.  Values of numeric variables are converted to string, as
            is, or converted using a numeric format under option format(%fmt) or decoded under option
            decode, in which case maxlength() may also be used to control the maximum label length used.
            By default, variables are added end to end:  punct(pchars) may be used to specify
            punctuation, such as a space, punct(" "), or a comma, punct(,).

        count(exp)                                                                  (allows by varlist:) 
            creates a constant (within varlist) containing the number of nonmissing observations of exp.
            Also see rownonmiss() and rowmiss() below.

        cut(varname), {at(#,#,...,#)|group(#)} [icodes label]
            may not be combined with by.  It creates a new categorical variable coded with the left-hand
            ends of the grouping intervals specified in the at() option, which expects an ascending
            numlist.

            at(#,#,...,#) supplies the breaks for the groups, in ascending order.  The list of break
            points may be simply a list of numbers separated by commas but can also include the syntax
            a(b)c, meaning from a to c in steps of size b.  If no breaks are specified, the command
            expects the option group().

            group(#) specifies the number of equal frequency grouping intervals to be used in the
            absence of breaks.  Specifying this option automatically invokes icodes.

            icodes requests that the codes 0, 1, 2, etc., be used in place of the left-hand ends of the
            intervals.

            label requests that the integer-coded values of the grouped variable be labeled with the
            left-hand ends of the grouping intervals.  Specifying this option automatically invokes
            icodes.

        diff(varlist)
            may not be combined with by.  It creates an indicator variable equal to 1 if the variables
            in varlist are not equal and 0 otherwise.

        ends(strvar) [, punct(pchars) trim [head|tail|last]]
            may not be combined with by.  It gives the first "word" or head (with the head option), the
            last "word" (with the last option), or the remainder or tail (with the tail option) from
            string variable strvar.

            head, last, and tail are determined by the occurrence of pchars, which is by default a
            single space (" ").

            The head is whatever precedes the first occurrence of pchars, or the whole of the string if
            it does not occur.  For example, the head of "frog toad" is "frog", and that of "frog" is
            "frog".  With punct(,), the head of "frog,toad" is "frog".

            The last word is whatever follows the last occurrence of pchars or is the whole of the
            string if a space does not occur.  The last word of "frog toad newt" is "newt", and that of
            "frog" is "frog".  With punct(,), the last word of "frog,toad" is "toad".

            The remainder or tail is whatever follows the first occurrence of pchars, which will be the
            empty string "" if pchars does not occur.  The tail of "frog toad newt" is "toad newt", and
            that of "frog" is "".  With punct(,), the tail of "frog,toad" is "toad".

            The trim option trims any leading or trailing spaces.

        fill(numlist)
            may not be combined with by.  It creates a variable of ascending or descending numbers or
            complex repeating patterns.  numlist must contain at least two numbers and may be specified
            using standard numlist notation; see numlist.  [if] and [in] are not allowed with fill().


        group(varlist) [, missing label lname(name) truncate(num)]
            may not be combined with by.  It creates a single variable taking on values 1, 2, ... for
            the groups formed by varlist.  varlist may contain numeric variables, string variables, or a
            combination of the two.  The order of the groups is that of the sort order of varlist.
            missing indicates that missing values in varlist (either . or "") are to be treated like any
            other value when assigning groups, instead of as missing values being assigned to the group
            missing.  The label option returns integers from 1 up according to the distinct groups of
            varlist in sorted order.  The integers are labeled with the values of varlist or the value
            labels, if they exist.  lname() specifies the name to be given to the value label created to
            hold the labels; lname() implies label.  The truncate() option truncates the values
            contributed to the label from each variable in varlist to the length specified by the
            integer argument num.  The truncate option cannot be used without specifying the label
            option.  The truncate option does not change the groups that are formed; it changes only
            their labels.

        iqr(exp)                                                                    (allows by varlist:) 
            creates a constant (within varlist) containing the interquartile range of exp.  Also see
            pctile().

        kurt(varname)                                                               (allows by varlist:) 
            returns the kurtosis (within varlist) varname.

        mad(exp)                                                                    (allows by varlist:) 
            returns the median absolute deviation from the median (within varlist) of exp.

        max(exp)                                                                    (allows by varlist:) 
            creates a constant (within varlist) containing the maximum value of exp.

        mdev(exp)                                                                   (allows by varlist:) 
            returns the mean absolute deviation from the mean (within varlist) of exp.

        mean(exp)                                                                   (allows by varlist:) 
            creates a constant (within varlist) containing the mean of exp.

        median(exp)                                                                 (allows by varlist:) 
            creates a constant (within varlist) containing the median of exp.  Also see pctile().

        min(exp)                                                                    (allows by varlist:) 
            creates a constant (within varlist) containing the minimum value of exp.

        mode(varname) [, minmode maxmode nummode(integer) missing]                  (allows by varlist:) 
            produces the mode (within varlist) for varname, which may be numeric or string.  The mode is
            the value occurring most frequently.  If two or more modes exist, the mode produced will be
            a missing value.  To avoid this, the minmode, maxmode, or nummode() options may be used to
            specify choices for selecting among the multiple modes.  minmode returns the lowest value,
            and maxmode returns the highest value.  nummode(#) will return the #th mode, counting from
            the lowest up.  Missing values are excluded from determination of the mode unless missing is
            specified.  Even so, the value of the mode is recorded for observations for which the values
            of varname are missing unless they are explicitly excluded, that is, by
            if varname < . or if varname != "".

        mtr(year income)
            may not be combined with by.  It returns the U.S. marginal income tax rate for a married
            couple with taxable income income in year year, where 1930 < year < 2004.  year and income
            may be specified as variable names or constants; e.g., mtr(1993 faminc), mtr(surveyyr
            28000), or mtr(surveyyr faminc).  A blank or comma may be used to separate income from year.

        pc(exp) [, prop]                                                            (allows by varlist:) 
            returns exp (within varlist) scaled to be a percentage of the total, between 0 and 100.  The
            prop option returns exp scaled to be a proportion of the total, between 0 and 1.

        pctile(exp) [, p(#)]                                                        (allows by varlist:) 
            creates a constant (within varlist) containing the #th percentile of exp.  If p(#) is not
            specified, 50 is assumed, meaning medians.  Also see median().

        rank(exp) [, [field|track|unique]]                                          (allows by varlist:) 
            creates ranks (within varlist) of exp; by default, equal observations are assigned the
            average rank.  The field option calculates the field rank of exp: the highest value is
            ranked 1, and there is no correction for ties.  That is, the field rank is 1 + the number of
            values that are higher.  The track option calculates the track rank of exp:  the lowest
            value is ranked 1, and there is no correction for ties.  That is, the track rank is 1 + the
            number of values that are lower.  The unique option calculates the unique rank of exp:
            values are ranked 1,...,#, and values and ties are broken arbitrarily.  Two values that are
            tied for second are ranked 2 and 3.

        rowfirst(varlist)
            may not be combined with by.  It gives the first nonmissing value in varlist for each
            observation (row).  If all values in varlist are missing for an observation, newvar is set
            to missing.

        rowlast(varlist)
            may not be combined with by.  It gives the last nonmissing value in varlist for each
            observation (row).  If all values in varlist are missing for an observation, newvar is set
            to missing.

        rowmax(varlist)
            may not be combined with by.  It gives the maximum value (ignoring missing values) in
            varlist for each observation (row).  If all values in varlist are missing for an
            observation, newvar is set to missing.

        rowmean(varlist)
            may not be combined with by.  It creates the (row) means of the variables in varlist,
            ignoring missing values; for example, if three variables are specified and, in some
            observations, one of the variables is missing, in those observations newvar will contain the
            mean of the two variables that do exist.  Other observations will contain the mean of all
            three variables.  Where none of the variables exist, newvar is set to missing.

        rowmin(varlist)
            may not be combined with by.  It gives the minimum value in varlist for each observation
            (row).  If all values in varlist are missing for an observation, newvar is set to missing.

        rowmiss(varlist)
            may not be combined with by.  It gives the number of missing variables in varlist for each
            observation (row).

        rownonmiss(varlist) [, strok]
            may not be combined with by.  It gives the number of nonmissing values in varlist for each
            observation (row)--this is the value used by rowmean() for the denominator in the mean
            calculation.

            String variables may not be specified unless option strok is also specified.  If strok is
            specified, string variables will be counted as containing missing values when they contain
            "".  Numeric variables will be counted as containing missing when their value is ">.".

        rowsd(varlist)
            may not be combined with by.  It creates the (row) standard deviations of the variables in
            varlist, ignoring missing values.

        rowtotal(varlist)
            may not be combined with by.  It creates the (row) sum of the variables in varlist, treating
            missing as 0.

        sd(exp)                                                                     (allows by varlist:) 
            creates a constant (within varlist) containing the standard deviation of exp.  Also see
            mean().

        seq() [, from(#) to(#) block(#)]                                            (allows by varlist:) 
            returns integer sequences.  Values start from from() (default 1) and increase to to() (the
            default is the maximum number of values) in blocks (default size 1).  If to() is less than
            the maximum number, sequences restart at from().  Numbering may also be separate within
            groups defined by varlist or decreasing if to() is less than from().  Sequences depend on
            the sort order of observations, following three rules: (1) observations excluded by if or in
            are not counted, (2) observations are sorted by varlist, if specified; and (3) otherwise,
            the order is that when called.  Note that no arguments are specified.

        skew(varname)                                                               (allows by varlist:) 
            returns the skewness (within varlist) of varname.  When skew() is specified, newvar will
            always be produced as type double.  The type specified by the user will be ignored.

        std(exp) [, mean(#) std(#)]
            may not be combined with by.  It creates the standardized values of exp.  The options
            specify the desired mean and standard deviation.  The default is mean(0) and std(1),
            producing a variable with mean 0, standard deviation 1.

        tag(varlist) [, missing]
            may not be combined with by.  It tags just one observation in each distinct group defined by
            varlist.  When all observations in a group have the same value for a summary variable
            calculated for the group, it will be sufficient to use just one value for many purposes.
            The result will be 1 if the observation is tagged and never missing, and 0 otherwise.
            Values for any observations excluded by either [if] or [in] are set to 0 (not missing).
            Hence, if tag is the variable produced by egen tag = tag(varlist), the idiom if tag is
            always safe.  missing specifies that missing values of varlist may be included.

        total(exp)                                                                  (allows by varlist:) 
            creates a constant (within varlist) containing the sum of exp.  Also see mean().

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-24 22:18