Announcement

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

  • dummy for panel data

    Hi,
    how to create dummy variable for panel data? I want to create a dummy for 130 districts for 3 years; 2010, 2012 and 2014. If the district has a cant then it should be 1 otherwise 0. How to do it for all 3 years?

  • #2
    Maryam:
    welcome to this forum.
    You may be looking for something along the following lines:
    Code:
    . use "http://www.stata-press.com/data/r15/nlswork.dta"
    (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
    
    . bysort idcode year: g flag=1 if race==1
    (8,354 missing values generated)
    
    . replace flag=0 if race!=1
    (8,354 real changes made)
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      What is a cant and how you recognise it in your data? Please give a data example.

      Comment


      • #4
        Nick Cox cant- cantonment is a dummy for infrastructure. If there is cant present in a district its 1 otherwise its 0.

        Comment


        • #5
          Thanks, but I still ask [editing slightly]

          how would you recognise it in your data? Please give a data example.
          See the FAQ Advice #12 for how to give a data example.
          Last edited by Nick Cox; 03 Mar 2019, 05:02.

          Comment


          • #6
            Thanks Nick Cox for your patience. Im not able to export a data ex from my stata but i took a screenshot. Will this help?
            Click image for larger version

Name:	dataex.PNG
Views:	1
Size:	24.4 KB
ID:	1486294

            Comment


            • #7
              I don't understand why you can't use dataex, and we explain in the place cited that screenshots aren't always much use. This one makes clear that

              1. You already have a variable CANTONMENT, which looks like an indicator (dummy) to me.

              2. Just possibly

              Code:
              egen has_cantonment = max(CANTONMENT), by(Distrcts)
              is what you want even though it would just equal CANTONMENT on the evidence given.

              See https://www.stata.com/support/faqs/d...ble-recording/ for the principle used.

              Comment


              • #8
                Thanks a lot!

                Comment

                Working...
                X