Announcement

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

  • Reshaping with non unique string variables

    Hello everyone!
    Please help me on this, I am really desperate by now.

    So I have a dataset (attached photo) and the regression I am trying to get would be reg hcount visit county
    however, I am trying to get all visit_id (visit_A, visit_B..) under one var visit with all i observations. and Same for hcount_id..
    so I did :
    reshape long hcounts_, i(county) j(id) string

    But then I get an error message :

    variable id does not uniquely identify the observations
    Your data are currently wide. You are performing a reshape
    long. You specified i(county) and j(id). In the current wide
    form, variable county should uniquely identify the
    observations.



    I think this is due to the fact that for each county (Houston, Stjohns...) I have each written multiple times : so I have Houston Houston Houston....

    So does anyone know how I can create a UNIQUE non string dummy variable for each county ?
    ie, Houston =1 if county=houston
    Attached Files
    Last edited by Lola Nait; 07 Nov 2019, 17:42.

  • #2
    Welcome to Statalist.

    The short answer is that the reshape command allows you to include more than one variable in the i() option, so you want to add date to the i() option.

    But given the layout of your data, along with reshaping the hcount_ variables, I think you also want to reshape the count_ and visit_ variables. Perhaps something like
    Code:
    reshape long visit_ counts_ hcounts_, i(county date) j(id) string
    will be what you want. I can't test this recommendation because even the latest version of Stata does not import data from pictures. So there may be other problems that this solution does not address.

    In future posts please consider providing example data useful for testing code.

    Be sure to use the dataex command to do this. If you are running version 15.1 or later, or a fully updated version 14.2, dataex is already part of your official Stata installation. If not, run ssc install dataex to get it. Either way, run help dataex and read the simple instructions for using it. dataex will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use dataex.

    Comment

    Working...
    X