Announcement

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

  • How to create a formla

    code year var2 top5
    1100 201712 5 1
    1100 201712 5 2
    1100 201712 5 3
    1100 201712 4.9 4
    1100 201712 4.8 5
    1200 201712 6 1
    1200 201712 5.9 2
    1200 201712 5.4 3
    1200 201712 5.4 4
    1200 201712 5.4 5
    1300 201712 6 1
    1300 201712 2 2
    1300 201712 1 3
    1300 201712 3 4
    1300 201712 2 5
    1300 201812 6 1
    1300 201812 6 2
    1300 201812 5 3
    1300 201812 4 4
    1300 201812 4 5

    Dear all ,this is a part of my data.As you can see I sort by code and year.I want to generate a variable.
    This variable requires a complicated calculation process. The process is as follows: First, I want to calculate {(1-2)^2+(2-3)^2+(3-4)^2+(4-5)^2}/100 in top5, 1 to 5in the formula must be brought into the value in var2.Thank u so much.
    Last edited by ke yuting; 15 Feb 2019, 00:58.

  • #2
    You didn't get a quick answer. 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.

    I can't understand what you are trying to calculate. If you really want to calculate {(1-2)^2+(2-3)^2+(3-4)^2+(4-5)^2}/100 then
    g a=((1-2)^2+(2-3)^2+(3-4)^2+(4-5)^2)/100

    does it. But I have no idea what the rest means.

    Comment

    Working...
    X