Announcement

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

  • keep variable in certain condition

    hello everyone, I want to keep variable maternal labor supply only in 2009 as covariance at baseline. could you please give me any code or advice?

    thank you!
    Attached Files

  • #2
    Hatsune:
    please explain what you're after. Thanks.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Hi Carlo!
      I want to find the effect of child enrollment in preschool on the EDI score, and maternal labor supply as a control variable, in the data set, the EDI score only existed in 2013 (endline) which I will use as the dependent variable, but for the maternal labor supply variable it is still there is data for 2009 (baseline), 2010 (midline), and 2013 (endline) whereas I only want to use maternal labor supply data available in 2009 (baseline).

      thank you for your answer.
      Last edited by hatsune miku; 23 Jun 2023, 00:46.

      Comment


      • #4
        Hatsune:
        an -if- clause can do the trick, as in the following toy-example:
        Code:
         use "C:\Program Files\Stata17\ado\base\a\auto.dta"
        (1978 automobile data)
        
        . regress price mpg i.rep78 if rep78==3
        note: 3.rep78 omitted because of collinearity.
        
              Source |       SS           df       MS      Number of obs   =        30
        -------------+----------------------------------   F(1, 28)        =     14.65
               Model |   123788982         1   123788982   Prob > F        =    0.0007
            Residual |   236582733        28  8449383.33   R-squared       =    0.3435
        -------------+----------------------------------   Adj R-squared   =    0.3201
               Total |   360371715        29  12426610.9   Root MSE        =    2906.8
        
        ------------------------------------------------------------------------------
               price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
        -------------+----------------------------------------------------------------
                 mpg |  -498.8875   130.3389    -3.83   0.001    -765.8747   -231.9003
             3.rep78 |          0  (omitted)
               _cons |   16124.28    2587.92     6.23   0.000     10823.17    21425.39
        ------------------------------------------------------------------------------
        
        .
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          how to use it for multiple variables? I mean maternal labor supply is just an example of my covariance variable.

          Comment


          • #6
            Hatsune:
            1) you can use multiple -if- conditions; or
            2) create new variables that include the year your intrested in:
            Code:
            gen mother_work_2009=mother_work if year==2009
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              I did your suggestion to generate a new variable, after I did the sum there was a difference in the number of observations, and I tried to drop the missing value but instead deleted all observations.
              Click image for larger version

Name:	WhatsApp Image 2023-06-23 at 15.49.48.jpeg
Views:	1
Size:	175.7 KB
ID:	1718164

              Comment


              • #8
                Hatsune:
                Stata uses listwise deletion by default.
                Hence:
                Code:
                 
                 gen mother_work_2009=mother_work if year==2009
                will generate missing values when year differs from 2009.

                No wonder that you remain with zero observations, then, as listwise deletion gets rid of all the observations with missing value in any of the variables.
                Kind regards,
                Carlo
                (Stata 19.0)

                Comment

                Working...
                X