Announcement

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

  • Stata Question- Is the code "gen var1=var2 if conditions" possible ?

    Hello,
    I am new to Stata and I would like to write a code.
    I want to determine the number of children in the women's current union (variable childincurunion).
    I have data on : the birth year of the children (variable yearbirthchild) the year of first marriage/cohabitation (yearofmarriage) and data on the total number of alive children that the woman had regarding the number of union that she may had (variable chebalive) .
    I am restricting my sample to the number of women who are currently married or living with a man and had only one union.
    gen childIncurrunion=0
    replace childincurrunion=1 if yearbirthchild>=yearofmarriage (if we believe that the couple has children when they are married and not)
    Then, (for this line stata says invalid syntax).
    gen numberchildincurrunion=0
    if childincurrunion=0
    replace numberchildincurrunion=totalnumberofchildren
    What's the problem with this syntax ? Is there a correct way to write this ?
    Thank you for your help.
    I really appreciate it

  • #2
    Salma:
    welcome to this forum.
    As per FAQ, please use CODE delimiters to share what you typed and what Stata gave you back. In addition, you can post an example/excerpt of your data via -dataex-. Thanks.
    As far as your question is concerned, please note that the -uf- clause needs a double == to work, as in the following toy-example (-regress- outcome table was omitted):
    Code:
    sysuse auto.dta
    regress price mpg if rep78==5
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Welcome Salma. As you are new to Stata, it would be a very good investment of time to read the Getting Started guide which is included as part of the PDF documentation with your Stata installation. Type -help getting started- to get started.

      Comment


      • #4
        Thank you both for your answers )
        Carlo - What you suggested worked !

        Salma
        (Stata 15.1 IC)

        Comment

        Working...
        X