Announcement

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

  • Best way to add variables from PRAMS data

    Hi,

    I am running into a slight problem. I want to add variables together. There is a question in PRAMS that asks where the mother received breastfeeding information from and then lists 5+ options (doctor, family, support group, etc.). In the codebook, each option is its own variable. I was wondering what the best way to "add" each possibility of groupings is. Right now, all I can think of is doing "if doctor==1 & nurse==1 | doctor==1 7 family==1 ..." (which could take a very long time because I want to have an option for 1-7 sources of information). Open to any suggestions that would make coding this Breastfeeding Information variable better.

  • #2
    Well, assuming that the option variables are all coded 0 for no, 1 for yes:
    Code:
    egen n_info_sources = rowtotal(doctor nurse family support_group /*etc.*/)
    will add them up for you. (The /*etc.*/ is there because you say there are 5+ options, but only four are explicitly mentioned in your post. All of them need to be listed in the code (or perhaps if they are all located consecutively in the data set you can get them all with -rowtotal(doctor-last_option)-.)

    That said, what are you trying to do with
    if doctor==1 & nurse==1 | doctor==1 7 family==1 ..
    Even assuming that the 7 is an easily-made typo for &, why are you repeating the -doctor == 1- part and alternating between & and |. Is your real goal not to add things up but to identify those respondents who used a doctor and at least one other source of information? If so, you can get that with
    Code:
    gen wanted = (doctor == 1) + max(nurse, family, support_group /*, etc.*/)

    Comment


    • #3
      puzzled me too, by "&" is shift-7. Clyde's rowtotal solution seems to do the trick.

      Comment


      • #4
        Khiara Lee It's worth defining your source for those unfamiliar (PRAMS = CDC Pregnancy Risk Assessment Monitoring System) and questionnaire version/phase (assuming it's 9.2?) to help.
        An aside is that there are more than those 5 categories available...and you can combine these yes/no responses with questions elsewhere on the instrument about other sources of breastfeeding info including the toll free number, home visits, etc depending on which questionnaire version you're using. (The number of possible/potential response options to add up (that is the denominator) varies by state (if they have a supplement) and version (not to mention respondent situation based on other items in the survey) so this seems potentially problematic IMO))


        In short, I'm not sure the usefulness of 'adding together' the number of yes's (1's) for these items or a subset of items (getting a higher number of 'sources' doesn't necessarily mean the person had more or better information and combines varied types of information sources together - distinguishing the various types (i.a., medical information, friends/network, media/online, etc) and settings/modes of breastfeeding information provision seems more useful here).

        I think more value might come from either conceptually collapsing similar items (Clyde's advice on coding to 1 if any of the desired responses are a 1 works for this) or better exploring combinations of information sources that often occur together (or when they occur together are associated with other behaviors).


        In terms of Stata code, in addition to the good advice above consider the use of the inlist function to make this easier. e.g.

        Code:
        gen anymedicalprofessional = 1 if inlist(1, doctor, nurse, specialist, HCN) //maybe include doula or health educator from V13?
        gen anyprintedmaterials = 1 if inlist(1, hotline, website, socialmedia)
        gen anyinformalnetworksource = 1 if inlist(1, family, supportgroup, other)
        etc...
        Last edited by eric_a_booth; 06 Aug 2025, 17:16.
        Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

        Comment


        • #5
          A note on #4: A command of the flavour

          Code:
          gen whatever = 1 if inlist(a, b, c)
          creates a variable with values 1 and missing while the superficially similar

          Code:
          gen whatever = inlist(a, b, c)
          creates a variable with values 1 and 0. Variables with values 1 and missing can't easily be added.

          See https://www.stata-journal.com/articl...article=dm0026 and https://journals.sagepub.com/doi/pdf...36867X19830921 if more discussion is needed.

          Comment

          Working...
          X