Announcement

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

  • Panel subsample

    Dear all,
    I have a large panel dataset (unbalanced panel) with almost 180 countries and I want to have different countries subsamples (regrouping the countries with the same characteristics altogether).

    What is the command to do so?

    thank you

    Best Regards,
    Last edited by mariem omar; 25 Sep 2018, 18:07.

  • #2
    There is no command for that purpose. You would have to write a few lines of code to do this. Had you shown an example of your data and explained what you mean by "the same characteristics", I might have been able to write it for you.

    Basically it will be a series of sequences like this:

    Code:
    preserve
    keep if some_condition_defining_a_subsample
    save a_filename_for_this_subsample, replace
    restore
    The material in italics is just placeholders for actual logical expressions and filenames corresponding to the subsamples you want to create.

    Comment


    • #3
      Thank you for your response!
      I have a gravity model with different dummies and bilateral trade flows between Tunisia and its partners. So I want to put countries with the "same" gdp, distance, language, religion ... altogether so i can have for example france italy germany together, Brazil, argentina... just like clustering!

      Comment


      • #4
        First, if you want specific help, you have to show an example of your data, using the -dataex- command. Your description gives me a general idea of what you have, but it is not enough to nail down the details of a code solution to your problem.

        Second, you have not defined "same" gdp, distance language, religion. My guess is that there are no two countries with the same GDP, so what you really mean is "close", but how close? And in what sense of "same language" to France, Italy, and Germany get grouped together? For that matter, Brazil's language is Portuguese, Argentina's is Spanish. And nowadays, even in the few countries that have an official state religion, it is generally only observed by a minority of people. So you need to come up with a better way of defining your groupings. And it has to be expressible as a logical expression that uses your variables, or functions of your variables, and logical operators like &, |, and !. Based on your examples, the criterion that comes to mind is that groupings are continents.

        If you are running version 15.1 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- to 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


        • #5
          Thank you
          the command data ex is not working...
          but i am trying to us
          Bobková B. (2014). “On Estimation of Gravity Equation: A Cluster Analysis” IES Working Paper 37/2014. IES FSV. Charles University.
          Attached Files

          Comment


          • #6
            Mariem:
            posting screenshots is greatly unhelpful for those interested in replying, as they cannot be elaborated on.
            That said, you might want somenthing along the following lines:
            Code:
            use "http://www.stata-press.com/data/r15/nlswork.dta"
            egen flag=group( age race grade )
            Kind regards,
            Carlo
            (Stata 18.0 SE)

            Comment


            • #7
              the command data ex is not working...
              Please show the exact -dataex- command you used, and show the output that Stata gave you. Note, that the command is a single word, -dataex-, not two words -data ex-. If you gave a legal -dataex- command and got error messages or wrong output, this would be the first report of a bug in -dataex-, and I'm sure that StataCorp would want to know about it. I think it is more likely that you used it incorrectly, and if you show us what you did and what happened, somebody an help you get it right.

              Comment

              Working...
              X