Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • I can't generate new variable when i set condition if old variables are lower than 0

    Hi all, I have monthly return of individual firms (AAM), and then I want to create new variable is negative_AAM = -2.25*(return_AAM)^0.88 if return_AAM <0. And my code is defined as follow:
    Code:
    bys month: ge AAM_n = (-2.25)*(return_AAM)^0.88 if return_AAM<0
    But this result doesn't seem work.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(month return_AAM negative_AAM)
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    600    -.00190831 .
    601   .0002052551 .
    601   .0002052551 .
    601   .0002052551 .
    601   .0002052551 .
    601   .0002052551 .
    601   .0002052551 .
    601   .0002052551 .
    601   .0002052551 .
    601   .0002052551 .
    601   .0002052551 .
    601   .0002052551 .
    601   .0002052551 .
    601   .0002052551 .
    601   .0002052551 .
    601   .0002052551 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    602   .0010537847 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    603  .00022332897 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    604  -.0022975826 .
    605 -.00014270443 .
    605 -.00014270443 .
    end
    format %tm month
    Can somebody tell me that my code is not correct in some where? Thank you very much!!
    Last edited by Tan Nguyen; 08 Feb 2022, 08:58.

  • #2
    This is a precedence problem. For example, Stata would parse
    -.00190831^0.88 as -(0.00190831^0.88) and give you what you want. That is, the minus sign is there treated as a negation operator. But if foo contains -0.00190831 then foo^0.88 is parsed as (-0.00190831)^0.88 -- which can't be done as Stata tries to power by taking logarithms first. That is, the minus sign is there part of the numerical value. You need more cautious code using abs() and sign().

    Comment

    Working...
    X