Announcement

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

  • Fixing a specific value within a column based on another variable when generating a new variable through a formula.

    Hello all,

    I recognize the title is probably a bit confusing so I am gonna try to illustrate what I want to do below:

    Consider that I already have the variables "F", "t" and "Beta", and I want to create a new column called "weighted beta", "weighted beta2" and so on. I will write these new variables according to the formula I want to use below but note that I have not been able to generate them yet. The idea is that the t-1 part will generate 0 division, causing stata to fill the cells with zeros, which is what I want, and also it will give the proper weight to my betas. The problem is that I do not know how to fix a beta in the formula...

    Code:
    F       t      Beta                    weighted beta                         weighted beta2         weighted beta3       weighted beta4
    1       1         0.7                          =(1/t)*0.7                           =(1/(t-1))*0.5=0          =(1/(t-2))*0.3=0           =(1/(t-3))*0.55=0
    1       2         0.5                          =(1/t)*0.7                           =(1/(t-1))*0.5              =(1/(t-2))*0.3=0           =(1/(t-3))*0.55=0
    1       3         0.3                          =(1/t)*0.7                           =(1/(t-1))*0.5              =(1/(t-2))*0.3               =(1/(t-3))*0.55=0
    1       4         0.55                        =(1/t)*0.7                           =(1/(t-1))*0.5              =(1/(t-2))*0.3                =(1/(t-3))*0.55
    2       1         0.3                          =(1/t)*0.3                           =(1/(t-1))*0.4=0          =(1/(t-2))*0.67=0          =(1/(t-3))*0.3=0
    2       2         0.4                          =(1/t)*0.3                           =(1/(t-1))*0.4              =(1/(t-2))*0.67=0          =(1/(t-3))*0.3=0
    2       3         0.67                        =(1/t)*0.3                           =(1/(t-1))*0.4              =(1/(t-2))*0.67              =(1/(t-3))*0.3=0
    2       4         0.3                          =(1/t)*0.3                           =(1/(t-1))*0.4              =(1/(t-2))*0.67              =(1/(t-3))*0.3
    So, as you can see, for each weighted beta I want to fix a certain value of "Beta" based on the respective "t"- value... Any ideas?

    Kind Regards,
    Birger

  • #2
    Im thinking something like this:

    By F: egen weighted beta= (1/t)*Betat=1 but is it even possible in Stata to use index in this manner?

    Comment


    • #3
      You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex. Being able to replicate your problem can be essential to helping you.

      You first xtset your data. Then you can use L. to generate lags. While you can also do this with x[_n-1], using the built in lags will guarantee you don't lag across panels.

      I understand equation for the first weighted beta, but I have no idea what it means to have two separate equal signs in the equation.

      It looks like you want something like:

      xtset F t
      g wb=Beta * (1/t)
      g wb2=F.Beta * (1/F.t)

      Or something.

      Comment

      Working...
      X