Announcement

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

  • Generating conditional variable

    u
    Last edited by Femi Oladunni; 14 Jun 2022, 07:37.

  • #2
    Code:
    generate A = B==1 & C==1 & D>7 & D<17

    Comment


    • #3
      Femi:
      you may be interested in something along the following lines:
      Code:
      . set obs 100
      
      
      . g double A=.
      
      
      . g double B=.
      
      
      . g double C=.
      
      
      . g D=4+ _n
      
      . foreach var of varlist A-C  {
        2. replace `var'=1 if D>7 & D<17
        3.   }
      
      
      .
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Great, thanks.

        I do not know why my initial post shows just "U".

        For the sake of those who might want to refer to the question and could find Øyvind and Carlo responses helpful, I will re-paste it below

        "I want to generate a variable A=1 if variable B==1 and Variable C==1 when Variable D is greater than 7 but less than 17".

        Comment

        Working...
        X