Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You've found a solution with <code>cond()</code>, but here's a couple of suggestions that might make modeling your data easier and help you avoid problems with issues that might arise when sorting by creating your <code>rank</code> variable (and I've got the <code>egen</code> solution that you asked about below):</p> <p>Paste the code below into your do-file editor and run it:</p> <pre><code>*---------------------------------BEGIN EXAMPLE clear inp str20 country str10 gdp year "USA" "$100m" 1960 "USA" "$200m" 1965 "Canada" "$60m" 1960 "Canada" "$120m" 1965 "USA" "$250m" 1970 "Mexico" "$90m" 1970 "Canada" "$800m" 1970 "Mexico" "$160m" 1960 "Mexico" "$220m" 1965 "Mexico" "$350m" 1975 end //1. destring gdp so that we can work with it destring gdp, ignore("$", "m") replace //2. Create GDP for 1960 var: bys country: g x = gdp if year==1960 bys country: egen gdp60 = max(x) drop x **you could also create balanced panels to see gaps in your data** preserve ssc install panels panels country year fillin country year li //take a look at the results win. to see how filled panel data would look restore //3. create a gdp variable for each year (reshape the dataset) drop gdp60 reshape wide gdp, i(country) j(year) **much easier to use this format for modeling su gdp1970 **here's a fake "outcome" or response variable to work with** g outcome = 500+int((1000-500+1)*runiform()) anova outcome gdp1960-gdp1970 //or whatever makes sense for your situation *---------------------------------END EXAMPLE </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload