Announcement

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

  • Grouping values within a variable?

    In a prior post I looked at https://www.statalist.org/forums/for...hin-a-variable I tried to derive an answer, but no response, so I thought I create a new post. I am working with panel data that is based on observations at the county level. I want to run a regression analysis but need to create control and treatment groups based on whether states expanded Medicaid during the 2010 health care reform or did not. I have 37 states adopted medicaid and 14 did not adopt Medicaid.

    I have a variable statenameabr (state name abbreviation) which I changed from string to numeric. In the prior post, it was recommend to use the -inlist- command. I thought I would use that as well since the -inlist- command can 2 and 255 arguments for reals but limited for string var.

    I suggested the following and not sure if that would work.

    Code:
    encode statenameabr, gen (statenameabr1)
    I am proposing the following to generate a 0/1 dummy for statemcaidexp where 1 = 37 states that expanded medicaid and 0 = 14 states that did not expand.

    Code:
    gen statemedicaid = 1 if inlist (statenameabr1, "AL", "AS", "AZ", "CA",....)

    My end goal is:
    1. I can look at the distribution of education, income, insurance status of people in states that have expanded medicaid compare to those that did not. I am thinking once I create the statemcaidexp variable i should be able to do that.
    2. Of the states in each group a further stratification of those to create a control and treatment group within each of the groups created in #1.

    Here are some of the variables I have in my data set. For goal #2, I would use the variable -ever_had_fqhc- and -wanted-
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte year float(n_county wanted ever_had_fqhc) str2 statenameabr
    15 1 1 1 "AL"
    18 1 1 1 "AL"
    17 1 1 1 "AL"
    16 1 1 1 "AL"
     8 1 1 1 "AL"
    13 1 1 1 "AL"
     6 1 1 1 "AL"
    14 1 1 1 "AL"
    12 1 1 1 "AL"
    10 1 1 1 "AL"
     4 1 1 1 "AL"
    11 1 1 1 "AL"
    17 2 1 1 "AL"
    18 2 1 1 "AL"
    16 2 1 1 "AL"
    15 2 1 1 "AL"
     6 2 1 1 "AL"
    12 2 1 1 "AL"
     4 2 1 1 "AL"
    11 2 1 1 "AL"
    14 2 1 1 "AL"
     8 2 1 1 "AL"
    10 2 1 1 "AL"
    13 2 1 1 "AL"
    17 3 1 1 "AL"
    15 3 1 1 "AL"
    18 3 1 1 "AL"
    16 3 1 1 "AL"
    13 3 1 1 "AL"
     8 3 1 1 "AL"
     6 3 1 1 "AL"
    14 3 1 1 "AL"
    11 3 1 1 "AL"
    12 3 1 1 "AL"
    10 3 1 1 "AL"
     4 3 1 1 "AL"
    17 4 1 1 "AL"
    18 4 1 1 "AL"
    15 4 1 1 "AL"
    16 4 1 1 "AL"
     4 4 1 1 "AL"
     8 4 1 1 "AL"
    14 4 1 1 "AL"
     6 4 1 1 "AL"
    10 4 1 1 "AL"
    12 4 1 1 "AL"
    13 4 1 1 "AL"
    11 4 1 1 "AL"
    18 5 1 1 "AL"
    17 5 1 1 "AL"
    15 5 1 1 "AL"
    16 5 1 1 "AL"
    10 5 1 1 "AL"
    12 5 1 1 "AL"
    13 5 1 1 "AL"
     4 5 1 1 "AL"
    11 5 1 1 "AL"
    14 5 1 1 "AL"
     6 5 1 1 "AL"
     8 5 1 1 "AL"
    15 6 1 1 "AL"
    17 6 1 1 "AL"
    16 6 1 1 "AL"
    18 6 1 1 "AL"
    13 6 1 1 "AL"
     6 6 1 1 "AL"
     8 6 1 1 "AL"
    14 6 1 1 "AL"
    11 6 1 1 "AL"
    10 6 1 1 "AL"
     4 6 1 1 "AL"
    12 6 1 1 "AL"
    17 7 1 1 "AL"
    16 7 1 1 "AL"
    18 7 1 1 "AL"
    15 7 1 1 "AL"
    12 7 1 1 "AL"
    14 7 1 1 "AL"
    13 7 1 1 "AL"
    10 7 1 1 "AL"
     8 7 1 1 "AL"
     4 7 1 1 "AL"
     6 7 1 1 "AL"
    11 7 1 1 "AL"
    17 8 1 1 "AL"
    18 8 1 1 "AL"
    15 8 1 1 "AL"
    16 8 1 1 "AL"
     8 8 1 1 "AL"
    11 8 1 1 "AL"
    14 8 1 1 "AL"
    12 8 1 1 "AL"
    13 8 1 1 "AL"
     6 8 1 1 "AL"
    10 8 1 1 "AL"
     4 8 1 1 "AL"
    15 9 1 1 "AL"
    16 9 1 1 "AL"
    17 9 1 1 "AL"
    18 9 1 1 "AL"
    end
    label values n_county n_county
    label def n_county 1 "Alabama Autauga", modify
    label def n_county 2 "Alabama Baldwin", modify
    label def n_county 3 "Alabama Barbour", modify
    label def n_county 4 "Alabama Bibb", modify
    label def n_county 5 "Alabama Blount", modify
    label def n_county 6 "Alabama Bullock", modify
    label def n_county 7 "Alabama Butler", modify
    label def n_county 8 "Alabama Calhoun", modify
    label def n_county 9 "Alabama Chambers", modify
    label var year "Reshaped Year variable panel data"
    label var n_county "group(statename countyname)"
    label var wanted "1 if n_county started out with 0 FQHCs and then got 1 at some point in time and "
    label var ever_had_fqhc "1= for all obs of any n_county that has had 1 or more FQHC's at any point in tim"
    label var statenameabr "State Name Abbreviation"

  • #2
    You can't use the -inlist()- function with your string variable statenameabr because -inlist()- with strings only accepts up to 10 arguments, and so your list will be too long.

    But if you use statenameabr1 and the corresponding numbers, then you can use -inlist()-. To see which numbers were assigned to which states, after the -encode- command run -label list statenameabr1-. Also, remember that this is Stata, so you need a 1/0 variable, not a 1/missing variable if you are going to work with it. So

    Code:
    gen statemedicaid = 1 if inlist(statenameabr1, list of appropriate numbers) // THIS IS INCORRECT  
    
    gen statemedicaid = inlist(statenameabr1, list of appropriate numbers) // THIS IS CORRECT

    Comment


    • #3
      Thanks Clyde. So once I create this 1/0 variable for var -statemedicaid- I would be able to identify states who expanded medicaid and those who did not. In a previous post in which you provided help on creating two variables -ever_had_fqhc- and -wanted- to identify counties that had FQHCs at least one or never had an FQHC. See post #20 in Creating a year identifier you provided help on how to create those variables.

      original code
      Code:
      replace fqhc = 0 if missing(fqhc)
      by n_county (year), sort: egen ever_had_fqhc = max(fqhc > 0)
      by n_county (year): gen wanted = (fqhc[1] == 0 & ever_had_fqhc)
      Now with the 1/0 variable for statemedicaid, can I modify the code and have to create 4 different variables with 2 for when statemedicaid=1 and statemedicaid=0?

      Comment


      • #4
        Now with the 1/0 variable for statemedicaid, can I modify the code and have to create 4 different variables with 2 for when statemedicaid=1 and statemedicaid=0?

        I don't understand. What are these 4 variables supposed to indicate?

        Comment


        • #5
          Sorry for not being clear Clyde Schechter. Thinking through this after creating the -statemedicaid- variable 1/0 I want to create treatment and control group. It probably would not be 4 variables but rather

          within the states grouped as having statemedicaid=1:
          treatment = presence of FQHC
          2 type of control groups:
          - control group with an FQHC
          - control group with no FQHC

          and I would want to test these same treatment and control vars when statemedicaid =0

          I previously created ever_had_fqhc and wanted but those variables seem to be arrays that will identify counties that within a time period they went from 0 to at least 1 FQHC or always had an FQHC but they are not treatment/control variables.

          So now that I have grouped values within the var statemedicaid.

          Hope that wasn't more confusing.

          Comment


          • #6
            I'm still confused.
            treatment = presence of FQHC
            2 type of control groups:
            - control group with an FQHC
            - control group with no FQHC
            contradicts itself. If treatment = presence of FQHC, then there can't be a control group with an FQHC. So what is the treatment condition?

            Comment


            • #7
              Hi Clyde. Since the topic is shifting a bit, I created a separate post here. Thanks for walking through this thinking with me.

              Comment


              • #8
                Clyde - just following up to say thanks for this help. I was able to create the statemedicaid variable.

                Comment

                Working...
                X