Announcement

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

  • replacing value of another row from the current row

    serial numprec pernum fchloc momloc firstchild nchild nchild2 age
    1184821 18 1 0 9+ 53
    1184821 18 2 0 9+ 9 52
    1184821 18 3 3 2 1 1 child 9 27
    1184821 18 4 2 1 child 9 26
    1184821 18 5 2 1 child 9 23
    1184821 18 6 2 0 childr 9 21
    1184821 18 7 2 1 child 9 19
    1184821 18 8 2 0 childr 9 16
    1184821 18 9 2 0 childr 9 14
    1184821 18 10 2 0 childr 9 12
    1184821 18 11 2 0 childr 9 10
    1184821 18 12 0 1 child 27
    1184821 18 13 0 1 child 23
    1184821 18 14 0 1 child 21
    1184821 18 15 15 12 1 0 childr 1 5
    1184821 18 16 16 13 1 0 childr 1 3
    1184821 18 17 17 14 1 0 childr 1 less tha
    1184821 18 18 18 7 1 0 childr 1 less tha
    existing variable nchild has a limit of 9 but there are data where the actual value is higher (this specific instance is not).
    I've created 3 new variables at an attempt to somehow add firstchildlocation to the mother

    Code:
    by bysort serial momloc: gen nchild2 = _N if momloc != 0
    gen firstchild = 1 if eldch[_n-pernum+momloc] == age & age < 18
    gen fchloc = pernum if firstchild == 1

    I would like to do, for example, for pernum3
    Code:
    replace momloc[_n-pernum+momloc] = momloc[_n] if firstchild == 1
    I understand that I can only do this the other way around.

    I've been searching on google for 'copying (and other similar words) values to different rows on stata'.

    Any kind of command or other "search terms" that are more in line with what I'm looking for would be much appreciated.
    Last edited by Henry Han WLG; 19 May 2018, 08:20.

  • #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. Many will be happier if you use Stata terms - we have observations, not rows. It would also help if your example were very carefully tailored to show your problem. Only include the variables you need. Also, I don't think you have a firstchild==1 in your example. Without that, we can't duplicate your problem. It would also help if you explain the structure of your data more. I don't know what all the identifiers are.

    I have trouble understanding firstchildlocation since it doesn't appear in your data sample. I'm not sure what you're doing, but a couple of observations. You probably want to change from strings like 10 childr to a variable equal 10. This can be done with the string functions that identify the first space and then another that copies from the beginning to that space. Then convert the number to a real.

    If everything is real, you can do by with egen and max to set values to the max for a group.




    Comment

    Working...
    X