Stata- Is there a way to store data like Python's dictionary or a hash map?

Parseltongue

Is there a way to store information in Stata similar to a dictionary in Python or a hash map in other languages?

I am iterating through variable lists that are appended with _1, _2, _3, _4, _5, _6, _7 ... _18 to delineate sections, and I want to sum the number of times the letters "DK" appear in each variable in each section. Right now I have 18 for loops, with each loop iterating through a different section, saving the 'sum' of the total number of DK's in a new variable called DK_1sum, DK_2sum, and then I later produce graphs of that data.

I'm wondering if there is a way to turn all this into a large For loop, and just append the data to a dictionary/array such that the data looks like:

{s1Sum, 25 
s2Sum, 56 ...
s18Sum, 101}

Is this possible?

Nick Cox

This could be stored in a Stata matrix, a Mata matrix or just ordinary Stata variables.

 gen count = . 
 gen which = _n 
 qui forval j = 1/18 { 
     scalar found = 0 
     foreach v of var *_`j' { 
             count if strpos(`v', "DK") 
             scalar found = scalar(found) + r(N) 
     }
     replace count = scalar(found) in `j' 
 } 
 list which count in 1/18 

For variation, here is a Stata matrix approach.

 matrix count = J(18,1,.) 
 qui forval j = 1/18 { 
     scalar found = 0 
     foreach v of var *_`j' { 
             count if strpos(`v', "DK") 
             scalar found = scalar(found) + r(N) 
     }
     matrix count[`j', 1] = scalar(found) 
 } 
 matrix list count

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Redis — best way to store a large map (dictionary)

From Dev

What is a good way to store static data? Like items and their stats, rewarddata or waypoints on a map for a towerdefense game

From Dev

Best way to store table like data

From Dev

Is there any way in angular to create a hash map like structure

From Dev

python syntax like PHP to store data

From Dev

Storage capacity of dictionary and want to store huge data into dictionary in python

From Dev

python class behaves like dictionary-or-list-data-like

From Dev

I would like to store some data of JSON response in the map

From Dev

java map string data to dictionary in python

From Dev

Best way to store data using APDU's?

From Dev

What's the correct way to store data in elasticsearch?

From Dev

Is there a better way to find specific value in a python dictionary like in list?

From Dev

Is there a better way to find specific value in a python dictionary like in list?

From Java

What's the cleanest way of applying map() to a dictionary in Swift?

From Dev

What is the best way to store data in Python?

From Dev

Easy way to store multiple data in Python 3

From Dev

What is the best way to store data in Python?

From Dev

What's the best way to store several values as a key in a map

From Dev

What data structure can I use to store some data tables and using keys like a dictionary in R?

From Dev

Python: Pulling data out of dictionary like a 2D array

From Dev

Python/Pandas:How to process a column of data like a dictionary

From Dev

Python dictionary like Json

From Dev

Store hash-like id in postgresql

From Dev

how to use of Hash map/dictionary to fetch values from data frame? faster alternate to for loop in R

From Dev

Rails session data - Store in a hash

From Dev

store txt data in hash table

From Dev

Can I store 50 mb of string type key value pair data in Java Hash Map

From Dev

Scala: Store parameter names and types in a hash map

From Dev

What's a good way to store large amounts of static data?

Related Related

  1. 1

    Redis — best way to store a large map (dictionary)

  2. 2

    What is a good way to store static data? Like items and their stats, rewarddata or waypoints on a map for a towerdefense game

  3. 3

    Best way to store table like data

  4. 4

    Is there any way in angular to create a hash map like structure

  5. 5

    python syntax like PHP to store data

  6. 6

    Storage capacity of dictionary and want to store huge data into dictionary in python

  7. 7

    python class behaves like dictionary-or-list-data-like

  8. 8

    I would like to store some data of JSON response in the map

  9. 9

    java map string data to dictionary in python

  10. 10

    Best way to store data using APDU's?

  11. 11

    What's the correct way to store data in elasticsearch?

  12. 12

    Is there a better way to find specific value in a python dictionary like in list?

  13. 13

    Is there a better way to find specific value in a python dictionary like in list?

  14. 14

    What's the cleanest way of applying map() to a dictionary in Swift?

  15. 15

    What is the best way to store data in Python?

  16. 16

    Easy way to store multiple data in Python 3

  17. 17

    What is the best way to store data in Python?

  18. 18

    What's the best way to store several values as a key in a map

  19. 19

    What data structure can I use to store some data tables and using keys like a dictionary in R?

  20. 20

    Python: Pulling data out of dictionary like a 2D array

  21. 21

    Python/Pandas:How to process a column of data like a dictionary

  22. 22

    Python dictionary like Json

  23. 23

    Store hash-like id in postgresql

  24. 24

    how to use of Hash map/dictionary to fetch values from data frame? faster alternate to for loop in R

  25. 25

    Rails session data - Store in a hash

  26. 26

    store txt data in hash table

  27. 27

    Can I store 50 mb of string type key value pair data in Java Hash Map

  28. 28

    Scala: Store parameter names and types in a hash map

  29. 29

    What's a good way to store large amounts of static data?

HotTag

Archive