hi everyone,
for the past few weeks I have studied the entropyetc and ineq commands.
I have found out that ineq is the appropriate command for the type of data that I am working with. However, I have found an issue I don't seem able to solve.
I am working with a large dataset of about 5,000 rows, but to explain the issue I do not need to use it. I will use instead a dummy dataset that reproduces the structure of my data, and the problem I am trying to solve.
To hopefully make things clearer, I would like to first show a simpler structure I was able to work with.
I start with a dataset of three variables: species, year and abundance.
I then use ineq to calculate (successfully) the shannon index, by year
the "shannon" variable was generated with this code:
The problems I find is when the data structure becomes slightly more complicated, like in the example below.
I want to calculate the entropy index separately for each year within each region. So, I should end up with 4 different indicators
a set for alaska 2019, one for alaska 2020, as well as one for minnesota 2019 and one for minnesota 2020.
But I cannot find the right code for it. I looked through the ineq help file, and tested a few different options, without success.
I tried something like the below:
of even swapping year and region around in the code. But it did not produce the results I would expect.
I would appreciate any suggestions/comments
Many thanks
Nicola
for the past few weeks I have studied the entropyetc and ineq commands.
I have found out that ineq is the appropriate command for the type of data that I am working with. However, I have found an issue I don't seem able to solve.
I am working with a large dataset of about 5,000 rows, but to explain the issue I do not need to use it. I will use instead a dummy dataset that reproduces the structure of my data, and the problem I am trying to solve.
To hopefully make things clearer, I would like to first show a simpler structure I was able to work with.
I start with a dataset of three variables: species, year and abundance.
I then use ineq to calculate (successfully) the shannon index, by year
the "shannon" variable was generated with this code:
Code:
ineq abundance, by (year) genent(shannon) * Example generated by -dataex-. For more info, type help dataex clear input str18 species str4 year byte abundance float shannon "conttontail rabbit" "2019" 13 2.2446363 "fox squirrel" "2019" 7 2.2446363 "gray fox" "2019" 11 2.2446363 "house cat" "2019" 5 2.2446363 "march rabbit" "2019" 3 2.2446363 "opossum" "2019" 22 2.2446363 "otter" "2019" 2 2.2446363 "raccoon" "2019" 20 2.2446363 "red fox" "2019" 4 2.2446363 "spotted skunk" "2019" 3 2.2446363 "striped skunk" "2019" 15 2.2446363 "wild cat" "2019" 7 2.2446363 "conttontail rabbit" "2020" 14 2.2341623 "fox squirrel" "2020" 7 2.2341623 "gray fox" "2020" 10 2.2341623 "house cat" "2020" 5 2.2341623 "march rabbit" "2020" 3 2.2341623 "opossum" "2020" 22 2.2341623 "otter" "2020" 1 2.2341623 "raccoon" "2020" 20 2.2341623 "red fox" "2020" 5 2.2341623 "spotted skunk" "2020" 3 2.2341623 "striped skunk" "2020" 14 2.2341623 "wild cat" "2020" 7 2.2341623 "conttontail rabbit" "2021" 13 2.2438474 "fox squirrel" "2021" 7 2.2438474 "gray fox" "2021" 11 2.2438474 "house cat" "2021" 5 2.2438474 "march rabbit" "2021" 2 2.2438474 "opossum" "2021" 21 2.2438474 "otter" "2021" 2 2.2438474 "raccoon" "2021" 21 2.2438474 "red fox" "2021" 4 2.2438474 "spotted skunk" "2021" 4 2.2438474 "striped skunk" "2021" 14 2.2438474 "wild cat" "2021" 7 2.2438474 end
I want to calculate the entropy index separately for each year within each region. So, I should end up with 4 different indicators
a set for alaska 2019, one for alaska 2020, as well as one for minnesota 2019 and one for minnesota 2020.
But I cannot find the right code for it. I looked through the ineq help file, and tested a few different options, without success.
I tried something like the below:
Code:
ineq abundance, by (region year) genent(shannon) and this returns an error ineq abundance, by (year) by (region) genent(shannon)
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str9 region str4 year str18 species byte abundance "alaska" "2019" "conttontail rabbit" 13 "alaska" "2019" "fox squirrel" 7 "alaska" "2019" "gray fox" 11 "alaska" "2019" "house cat" 5 "alaska" "2019" "march rabbit" 3 "alaska" "2019" "opossum" 22 "alaska" "2019" "otter" 2 "alaska" "2019" "raccoon" 20 "alaska" "2019" "red fox" 4 "alaska" "2019" "spotted skunk" 3 "alaska" "2019" "striped skunk" 15 "alaska" "2019" "wild cat" 7 "alaska" "2020" "conttontail rabbit" 14 "alaska" "2020" "fox squirrel" 7 "alaska" "2020" "gray fox" 10 "alaska" "2020" "house cat" 5 "alaska" "2020" "march rabbit" 3 "alaska" "2020" "opossum" 22 "alaska" "2020" "otter" 1 "alaska" "2020" "raccoon" 20 "alaska" "2020" "red fox" 5 "alaska" "2020" "spotted skunk" 3 "alaska" "2020" "striped skunk" 14 "alaska" "2020" "wild cat" 7 "minnesota" "2019" "conttontail rabbit" 10 "minnesota" "2019" "fox squirrel" 5 "minnesota" "2019" "gray fox" 14 "minnesota" "2019" "house cat" 3 "minnesota" "2019" "march rabbit" 7 "minnesota" "2019" "opossum" 22 "minnesota" "2019" "otter" 4 "minnesota" "2019" "raccoon" 28 "minnesota" "2019" "red fox" 2 "minnesota" "2019" "spotted skunk" 13 "minnesota" "2019" "striped skunk" 23 "minnesota" "2019" "wild cat" 7 "minnesota" "2020" "conttontail rabbit" 12 "minnesota" "2020" "fox squirrel" 6 "minnesota" "2020" "gray fox" 15 "minnesota" "2020" "house cat" 4 "minnesota" "2020" "march rabbit" 9 "minnesota" "2020" "opossum" 23 "minnesota" "2020" "otter" 2 "minnesota" "2020" "raccoon" 24 "minnesota" "2020" "red fox" 4 "minnesota" "2020" "spotted skunk" 14 "minnesota" "2020" "striped skunk" 24 "minnesota" "2020" "wild cat" 8 end
I would appreciate any suggestions/comments
Many thanks
Nicola
Comment